[Haskell] Signature error because the order

Simon Peyton-Jones simonpj at microsoft.com
Thu Jan 14 11:58:32 EST 2010


In Haskell, the context of all functions in a mutually recursive group must be identical.
http://haskell.org/onlinereport/decls.html#generalization

Simon

From: haskell-bounces at haskell.org [mailto:haskell-bounces at haskell.org] On Behalf Of Luis Cabellos
Sent: 14 January 2010 11:26
To: haskell at haskell.org
Subject: [Haskell] Signature error because the order

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/06988206/attachment-0001.html


More information about the Haskell mailing list