[Haskell-cafe] Can someone explain this typing restriction?
Bernard James POPE
bjpop at csse.unimelb.edu.au
Mon Aug 14 09:40:02 EDT 2006
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.html]
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.
More information about the Haskell-Cafe
mailing list