"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

Reply via email to