Implict parameters and monomorphism
Lennart Augustsson
augustss@augustsson.net
Thu, 3 May 2001 10:24:22 -0400 (EDT)
OK, so since noone liked my original example here's another one.
It involves no defaulting and no classes in the funny function definition.
-- Here's the type signature that makes a difference.
--fun :: a -> Char
fun x = const (fun x) (fun True)
fix f = let x = f x in x
class C a where
m :: a -> String
instance C Char where
m _ = "has signature"
instance C Bool where
m _ = "no signature"
main = putStrLn (m (fix fun))
It is not at all surprising that you can write this. Originally
type signatures only allowed you to put a signature that was
more specific.
Polymorhic recursion on the other hand allows you to make the
type more general by putting a type signature on a definition.
Combining these you can make the signature be incomparable to
the deduced type. Using the class system you can then dispatch
on the type and get different behaviour.
-- Lennart