Is there a Haskell (GHC) extension for partial type synonym instances?

不想你离开。 提交于 2019-12-07 05:26:56

问题


Using the extension TypeSynonymInstances it is possible to write an instance like that:

instances MyClass String where ...

Using newtype it is possible to declare an instance like that:

newtype Kleisli m a b = Kleisli (a -> m b)

instance MyClass (Kleisli m) where ...

I now that it is not possible to do the following:

type Kleisli m a b = a -> m b

instance MyClass (Kleisli m) where ...

Now is there an extension that allows me to do so? If not, what problems prohibit such an extension?


回答1:


Haskell doesn't allow partially applied type synonyms ever since deciding equality between a type and a partially applied type synonym is equivalent to deciding whether two functions are equal. This is undecidable in general.

Recall that type synonyms are type level functions (that happen to be parametric in their arguments).

This is why it's generally encouraged to rely on partial application as much as possible in the definition of a type synonym. Though this doesn't seem possible in your case.



来源:https://stackoverflow.com/questions/22665556/is-there-a-haskell-ghc-extension-for-partial-type-synonym-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!