On Fri, 05 Oct 2001 21:25:57 +0200, Karl-Filip Faxen wrote:
>The monomorphism restriction goes like this in my inference rules:
>
>If a declaration group contains a pattern binding with a nonvariable pattern
>or one where there is no type signature for the variable, then the context
>parts of the type schemes derived for the bound variables must be empty.
>
>class IsNil a where
>�isNil :: a ->�Bool
>
>f x y = let g = isNil
>�����in (g x, g y)
I'm still having a lot of trouble grasping and comprehending this "monomorphism
restriction". It just doesn't feel right, and I keep having a lot of trouble juggling
all the descriptions I found on the web. So, I'll don my newbie hat and start asking
all the obvious questions.
I hope I don't annoy too much. I know there are people tired of discussing this,
but the thing is that this monomorphism restriction is something very easy to bump
into (I have), but all the definitions out there seem to be unable to seep in.
Especially the one in the Haskell Report, BTW.
>"If a declaration group"
Meaning something like "let g = isNil" up there?
>"contains a pattern binding with a nonvariable pattern"
Meaning... what exactly?
>"or one [pattern binding] where there is no type signature for the variable"
Meaning "g = isNil" above, without type signature for "g"?
>"then the context parts of the type schemes derived for the bound variables must be
>empty"
Meaning that in "let g = ...", "g" cannot be "g :: <context> => <type>" unless the
context is explicitly given?
Hmmm... This still sounds like nonsensical (as in counterintuitive and artificial)
to me. In a definition like "let g = isNil" there cannot be any compelling reason to
give "g" any type different than the type of "isNil".
>The monomorphism restriction applies to the binding of "g" since
>there is no type signature. Thus it is not legal to derive
>"forall a . IsNil a =>�a ->�Bool",
Ok... This is probably the one explanation that has begun to make an impact in my
mind.
>but two legal possibilities are
>- forall b . [b] ->�Bool, and
Choosing an explicit instance of IsNil. But this sounds nonsensical to me, too. No
instance should be choosing unless the specific instance type is forced by the
definition. Otherwise, if there are two insances, which one would it choose?
>- a ->�Bool (without quantification and with "IsNil a" among the predicates).
This is something I didn't understand either. Which predicates?
Thanx for your patience O:-)
Salutaciones,
JCAB
email: [EMAIL PROTECTED]
ICQ: 101728263
The Rumblings are back: http://www.JCABs-Rumblings.com
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell