RE: Why is this function type-correct
4 Mar
2002
4 Mar
'02
2:23 p.m.
Recently, I wrote a function similar to
x :: a x = x 42
which is type-correct (Hugs, Ghc, THIH). Still, from the expression it is clear that the type shoud have a function type. The definition
x :: a -> b x = x 42
is equally well accepted, though I can't see why this type would be correct. (I'd expect it to be too general.)
In two words: polymorphic recursion. You'll find that the compiler won't be able to derive a type for 'x' in either of the two examples you gave, but x has several types the most general of which is 'forall a. a' (ie. your first example). The fact that x has type 'forall a. a' is also a useful hint as to its behaviour - the only value that has such a type is bottom. Cheers, Simon
8943
Age (days ago)
8943
Last active (days ago)
0 comments
1 participants
participants (1)
-
Simon Marlow