polymorphic instances for typeclasses in Mercury language
Consider next declaration:
:- type wrap(T) ---> wrap(T).
:- inst wrap(I) ---> wrap(I).
:- typeclass infer_wrap(A, B) <= ((A -> B)).
:- instance infer_wrap(A, wrap(A)).
Mercury (10.04) produces:
monad.m:011: In instance declaration for `monad.infer_wrap(A, monad.wrap(A))': monad.m:011: the first arg is a type variable
Even without functional dependency it will not allow to declare instance with type variables.
Am I missing something or Mercury doesn't allow instances which doesn't end with ground instance?
Is there any way to declare instance for polymorphic type which is wrapper for any type (without constraints)? Maybe there exists some special typeclass like all_types(T)
?
Short answer:
Mercury doesn't support type variables in instance declarations. (which is what the compiler is complaining about).
Long answer:
There is no way create such a typeclass instance. Since the typeclass will be valid for all values of A maybe you don't need a typeclass at all. But it looks like you're trying to create Monads, currently this is impossible and we have no plans to support it in the immediate future
链接地址: http://www.djcxy.com/p/43518.html上一篇: 不清楚Haskell选择了哪个实例
下一篇: Mercury语言中的类型类的多态实例