[Haskell] Signature error because the order
zhen.sydow at gmail.com
Thu Jan 14 06:26:14 EST 2010
I found than this piece of code causes an error in GHC ( *
data Tree a = Leaf a | Node (Tree a) (Tree a)
--prettyShow :: (Show a, Num a) => Tree a -> String -- WORKS
prettyShow :: (Num a, Show a) => Tree a -> String -- FAILS
prettyShow (Leaf a) = show a
prettyShow (Node a b) = (simple a) ++ (simple b)
simple :: (Show a, Num a) => Tree a -> String
simple (Leaf x) = prettyShow (Leaf x)
simple x = "(" ++ prettyShow x ++ ")"
With the error:
Couldn't match expected type `Show a'
against inferred type `Num a1'
When matching the contexts of the signatures for
prettyShow :: forall a. (Num a, Show a) => Tree a -> String
simple :: forall a. (Show a, Num a) => Tree a -> String
The signature contexts in a mutually recursive group should all be
When generalising the type(s) for prettyShow, simple
Failed, modules loaded: none.
But if I change the order of *Show* and *Num* in the signature of *
prettyShow* it works.
It's a GHC problem? it's normal than signature is order-dependent?
I use *GHC 6.10.3*
Thanks, Luis Cabellos
LC, ("There is no Dana, only Zuul." - Cazafantasmas )
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell