RE: Why is this function type-correct
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 ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Why is this function type-correct
Rijk J. C. van Haaften [EMAIL PROTECTED] wrote: 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.) For what reasons are these types considered correct? When you say x :: a you are asking that the compiler check that everything you say about x is consistent with x being acceptable where /any/ type is required. In the application x 42, it requires that x be a function, which is fine, because x has any type, and this includes functions. When you say x = x 42, this requires that the type returned from x 42 is the same as the type of x, again fine because if x::a, then x:: Integer - a also, so x 42:: a. It works out in practise because x = x 42 gives x the value bottom, and bottom::a for all a. Jón -- Jón Fairbairn [EMAIL PROTECTED] 31 Chalmers Road [EMAIL PROTECTED] Cambridge CB1 3SZ+44 1223 570179 (after 14:00 only, please!) ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: Why is this function type-correct
mån 2002-03-04 klockan 15.11 skrev Rijk J. C. van Haaften: Hello, 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. It might interest you to know that this function is also type correct: x :: x x = x x x x x x I would like to see a compiler derive that type though... Regards, Martin -- [ http://www.dtek.chalmers.se/~d95mback/ ] [ PGP: 0x453504F1 ] [ UIN: 4439498 ] Opinions expressed above are mine, and not those of my future employees. SIGBORE: Signature boring error, core dumped ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell