Monomorphism, monomorphism...

Juan Carlos Arévalo Baeza
Fri, 5 Oct 2001 19:02:50 -0700

On Fri, 05 Oct 2001 21:25:57 +0200, Karl-Filip Faxen wrote:

>The monomorphism restriction goes like this in my inference=
>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
>=A0isNil :: a ->=A0Bool
>f x y =3D let g =3D isNil
>=A0=A0=A0=A0=A0in (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 =3D 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 =3D 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 =3D ...", "g" cannot be "g :: <context>=
 =3D> <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 =3D 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"=
>there is no type signature. Thus it is not legal to derive
>"forall a . IsNil a =3D>=A0a ->=A0Bool",

   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] ->=A0Bool, 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=

>- a ->=A0Bool (without quantification and with "IsNil a" among the=

   This is something I didn't understand either. Which=

   Thanx for your patience O:-)

ICQ: 101728263
The Rumblings are back: