Implict parameters and monomorphism
Simon Peyton-Jones
simonpj@microsoft.com
Fri, 4 May 2001 03:40:53 -0700
Now that is a *really* amazing example. I had no
idea that polymorphic recursion would do this. =20
I withdraw my claim that a type signature can't change the answer.
But I'm worried.
Simon
| -----Original Message-----
| From: Lennart Augustsson [mailto:augustss@augustsson.net]=20
| Sent: 03 May 2001 15:24
| To: C.Reinke@ukc.ac.uk; qrczak@knm.org.pl
| Cc: haskell@haskell.org
| Subject: Re: Implict parameters and monomorphism
|=20
|=20
| OK, so since noone liked my original example here's another=20
| one. It involves no defaulting and no classes in the funny=20
| function definition.
|=20
| -- Here's the type signature that makes a difference.
| --fun :: a -> Char
| fun x =3D const (fun x) (fun True)
|=20
| fix f =3D let x =3D f x in x
|=20
| class C a where
| m :: a -> String
|=20
| instance C Char where
| m _ =3D "has signature"
|=20
| instance C Bool where
| m _ =3D "no signature"
|=20
| main =3D putStrLn (m (fix fun))
|=20
|=20
| It is not at all surprising that you can write this. =20
| Originally type signatures only allowed you to put a=20
| signature that was=20
| more specific.
| Polymorhic recursion on the other hand allows you to make the=20
| type more general by putting a type signature on a=20
| definition. Combining these you can make the signature be=20
| incomparable to the deduced type. Using the class system you=20
| can then dispatch on the type and get different behaviour.
|=20
| -- Lennart
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
|=20