Are there “type-level combinators”? Will they exist in some future?

前端 未结 3 859
不思量自难忘°
不思量自难忘° 2020-12-31 03:47

Much of what makes haskell really nice to use in my opinion are combinators such as (.), flip, $ <*> and etc. It fe

3条回答
  •  别那么骄傲
    2020-12-31 04:30

    Your question makes sense, but the answer is: no, it's not currently possible.

    The problem is that (in GHC Haskell's type system) you can't have lambdas at the type level. For anything you might try that looks like it could emulate or achieve the effect of a type level lambda, you will discover that it doesn't work. (I know, because I did.)

    What you can do is declare your Flip newtypes, and then write instances of the classes you want for them, painfully with the wrapping and the unwrapping (by the way: use record syntax), and then clients of the classes can use the newtypes in type signatures and not have to worry about the details.

    I'm not a type theorist and I don't know the details of why exactly we can't have type level lambdas. I think it was something to do with type inference becoming impossible, but again, I don't really know.

提交回复
热议问题