[Haskell] Signature error because the order
Luis Cabellos
zhen.sydow at gmail.com
Thu Jan 14 06:26:14 EST 2010
Hi,
I found than this piece of code causes an error in GHC ( *
http://haskell.pastebin.com/m5e3f4a4c* ):
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:
test.lhs:14:0:
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
identical
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 [1984])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell/attachments/20100114/3d68a89f/attachment.html
More information about the Haskell
mailing list