[Haskell-cafe] Problem with haskell types

Anupam Jain ajnsit at gmail.com
Fri Jul 30 16:26:49 EDT 2010


I am having trouble getting a small program to compile. The helpful folks at
#haskell created a version of the program that does compile -
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=28406#a28408 but it is not
very clear to them (and to me) why the original program wouldn't type
compile in the first place.

Here's the program that refuses to compile -

module Delme () wheredata DecisionState = A | B | C | Dd_test :: Eq b
=> b -> b -> DecisionState -> DecisionState -> ()d_test test testVal
trueState falseState =    if (test == testVal)     then d trueState
 else d falseStated :: DecisionState -> ()d A = d_test True True B Cd
B = d_test 1 2 C Dd C = d_test True False A Bd D = ()

I get an error like -

    Contexts differ in length
      (Use -XRelaxedPolyRec to allow this)
    When matching the contexts of the signatures for
      d_test :: forall b.
                (Eq b) =>
                b -> b -> DecisionState -> DecisionState -> ()
      d :: DecisionState -> ()
    The signature contexts in a mutually recursive group should all be
    When generalising the type(s) for d_test, d

Putting in the extension does get the program to type check but the original
program should have type compiled in the first place.

The ironic thing we discovered is that if we remove the type declaration for
'd', the program type checks, and GHC then derives the exact same type which
we removed!

Can some of the smarter people in the room please shed more light on this?

-- Anupam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100730/297b5dce/attachment.html

More information about the Haskell-Cafe mailing list