Can someone explain this typing restriction?

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....] 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

On Mon, Aug 14, 2006 at 02:17:05PM +0200, Tim Walkenhorst wrote:
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
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....]
This probably doesn't answer everything, but it is discussed in the following section of the Haskell Language Report: http://haskell.org/onlinereport/decls.html#sect4.5.2 A problem with the Report is that sometimes it tells you the rules, but it doesn't always justify them with detailed comments. I had a feeling this was discussed in "Typing Haskell in Haskell" by Mark Jones, but after a quick skim I can't find it again (I thought it would be in Section 11.6 of his paper). Cheers, Bernie.

Gerrit van den Geest wrote:
I had a feeling this was discussed in "Typing Haskell in Haskell" by Mark Jones, but after a quick skim I can't find it again (I thought it would be in Section 11.6 of his paper).
It is, on page 35 (section 11.6.3) of "Typing Haskell in Haskell" by Mark Jones.
Quote: "This is a consequence of a throw-away comment specifying that all explicit type signatures in a binding group must have the same context up to renaming of variables. This is a syntactic restriction that can easily be checked prior to type checking. Our comment here, however, suggest that it is unnecessarily restrictive." I agree with Mark Jones, the Haskell compiler Helium for example doesn't have this restriction. I think this issue is also related to the following Haskell' ticket: http://hackage.haskell.org/trac/haskell-prime/ticket/65 Gerrit

I had a feeling this was discussed in "Typing Haskell in Haskell" by Mark Jones, but after a quick skim I can't find it again (I thought it would be in Section 11.6 of his paper).
It is, on page 35 (section 11.6.3) of "Typing Haskell in Haskell" by Mark Jones.
Now you got me hooked. Where can I find his paper? The link in the Haskell-wiki[1] seems to be dead... Thanks, Tim [1] http://www.haskell.org/haskellwiki/Research_papers/Type_systems

Tim Walkenhorst wrote:
I had a feeling this was discussed in "Typing Haskell in Haskell" by Mark Jones, but after a quick skim I can't find it again (I thought it would be in Section 11.6 of his paper).
It is, on page 35 (section 11.6.3) of "Typing Haskell in Haskell" by Mark Jones.
Now you got me hooked. Where can I find his paper? The link in the Haskell-wiki[1] seems to be dead...
I don't know, I've encountered the same problems. Fortunately I have a printed version on my desk. Gerrit

On Aug 14, 2006, at 4:52 PM, Gerrit van den Geest wrote:
Tim Walkenhorst wrote:
I had a feeling this was discussed in "Typing Haskell in Haskell" by Mark Jones, but after a quick skim I can't find it again (I thought it would be in Section 11.6 of his paper).
It is, on page 35 (section 11.6.3) of "Typing Haskell in Haskell" by Mark Jones.
Now you got me hooked. Where can I find his paper? The link in the Haskell-wiki[1] seems to be dead...
I don't know, I've encountered the same problems. Fortunately I have a printed version on my desk.
Gerrit
It can be found here: http://citeseer.ist.psu.edu/424440.html

It can be found here: http://citeseer.ist.psu.edu/424440.html
Thanks! Actually I've seen this page before, but was too retarded to figure that you can access the actual document there. I thought it was just an abstract... (*embarrassed*)

Google Scholar is often quite handy for this sort of situation.
http://scholar.google.com/scholar?q=typing-haskell-in-haskell+jones
Jared.
On 8/14/06, Tim Walkenhorst
It can be found here: http://citeseer.ist.psu.edu/424440.html
Thanks! Actually I've seen this page before, but was too retarded to figure that you can access the actual document there. I thought it was just an abstract... (*embarrassed*)
participants (5)
-
Bernard James POPE
-
Gerrit van den Geest
-
Jared Updike
-
Nico Kuipers
-
Tim Walkenhorst