I've stumbled over the following (code *extremely* simplified):

f :: Bool
f = g 1

g :: Num a => a -> Bool
g _ = f

This results in the following error message (on GHC):

   Contexts differ in length
   When matching the contexts of the signatures for
     f :: Bool
     g :: forall a. (Num a) => a -> Bool
The signature contexts in a mutually recursive group should all be identical

A similar problem is described in: darcs.haskell.org/haskore/docs/Tutorial.pdf on page 128.

My first question is:

1) Is there a name for this restriction: I can't clearly identify it as some case of Let-Bound Polymorphism or the monomorphism restriction. [http://www.cs.auckland.ac.nz/references/haskell/haskell-intro-html/pitfalls.html]

2) What exactly is the problem with it?

3) What's the best workaround?

I've first tried to add an abundance of explicit type-annotations like f = (g::Int->Bool) 1 to it, but it doesn't work.

Then, I found a solution, but it's awkward:

f :: Bool
f = g f 1

g :: Num a => Bool -> a -> Bool
g f _ = f

As you may have guessed, the actual code is a bit more complicated than this. Basically I interpret a symbol in a syntax-tree which can belong to different type-classes. When doing that, other more general symbols must be evaluated. An indirect recursion (potentially) occurs...

I hope this hasn't been done to death yet. If it has, please just answer question one so that I can read up on it...

Thank you,
Tim

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to