When are higher kinded types useful?

后端 未结 5 1582
一向
一向 2021-01-29 18:21

I\'ve been doing dev in F# for a while and I like it. However one buzzword I know doesn\'t exist in F# is higher-kinded types. I\'ve read material on higher-kinded types, and

5条回答
  •  遇见更好的自我
    2021-01-29 19:05

    For a more .NET-specific perspective, I wrote a blog post about this a while back. The crux of it is, with higher-kinded types, you could potentially reuse the same LINQ blocks between IEnumerables and IObservables, but without higher-kinded types this is impossible.

    The closest you could get (I figured out after posting the blog) is to make your own IEnumerable and IObservable and extended them both from an IMonad. This would allow you to reuse your LINQ blocks if they're denoted IMonad, but then it's no longer typesafe because it allows you to mix-and-match IObservables and IEnumerables within the same block, which while it may sound intriguing to enable this, you'd basically just get some undefined behavior.

    I wrote a later post on how Haskell makes this easy. (A no-op, really--restricting a block to a certain kind of monad requires code; enabling reuse is the default).

提交回复
热议问题