[Haskell-cafe] classes with types which are wrapped in

Miguel Mitrofanov miguelimo38 at yandex.ru
Fri Jan 22 11:07:12 EST 2010


Wrap it in a newtype. That's the only way I know.

Andrew U. Frank wrote:
> i encounter often a problem when i have a class with some operations (say 
> class X with push)  applied to a type A b. I then wrap A in a type A_sup, with 
> some more type parameters and i cannot write a instance of class A_sup because 
> i have a kind mismatch. any suggestions? (reordering of the type parameters of 
> A_sup is not a solution, because another class operates on this parameter) 
> 
> here a simplistic case (i know that A could be reduced to [], my real cases 
> are more complicated).
> 
> data A b = A b [b]
> 
> data Asup x ab y = Asup x ab y
> 
> class X a b where
>     push :: b -> a b -> a b
> 
> instance X A Int where
>     push b' (A b bs) = A b' (b:bs)
> 
> instance X Asup Char Int Float where
>     push b' (Asup a b c) = Asup a (push b' b) c
> 
> -- this does not compile because the number of type arguments for X is wrong.
> 
> if i try with a type
> 
> type A_2 b = Asup Char (A b) Float
> 
> instance X A_2 Int where
>     push b' (Asup a b c) = Asup a (push b' b) c
> 
> (and --TypeSynonymInstances) i get:
> 
> Type synonym `A_2' should have 1 argument, but has been given 0
>     In the instance declaration for `X A_2 Int'
> 
> what is the solution? thank you!
> andrew
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 


More information about the Haskell-Cafe mailing list