Snippets tagged trait

  • F# version of Type Classes from OO Perspective

    This is the F# translation of the Scala program written for https://functional.works-hub.com/blog/Type-classes-from-OO-perspective. F# doesn't have implicits, so type classes don't work. However, it's interesting to see just how close you can come by passing an instance of the implementation. By flipping the parameters, you can use partial application to create type-specific functions. Here, we follow the use of the interface, but we could also use statically resolved type parameters to structurally infer different implementations.

    4 people like this

    Posted: 7 years ago by Ryan Riley

  • F# SRTP of Type Classes from OO Perspective

    Similar to http://fssnip.net/7Tr, this implementation translates the Scala from https://functional.works-hub.com/blog/Type-classes-from-OO-perspective but uses statically resolved type parameters to show how something similar could be done with computation expression instances. It's really too bad you have to pass an instance of the implementation. It would be nice to be able to specify a module or class with a static member.

    3 people like this

    Posted: 7 years ago by Ryan Riley