Revamping the numeric classes
Marcin 'Qrczak' Kowalczyk
mk167280@students.mimuw.edu.pl
Thu, 8 Feb 2001 11:09:35 +0100 (CET)
On Thu, 8 Feb 2001, Tom Pledger wrote:
> nice answer: give the numeric literal 10 the range type 10..10, which
> is defined implicitly and is a subtype of both -128..127 (Int8) and
> 0..255 (Word8).
What are the inferred types for
f = map (\x -> x+10)
g l = l ++ f l
? I hope I can use them as [Int] -> [Int].
> x + y + z -- as above
>
> --> (x + y) + z -- left-associativity of (+)
>
> --> realToFrac (x + y) + z -- injection (or treating up) done
> -- conservatively, i.e. only where needed
What does it mean "where needed"? Type inference does not proceed
inside-out. What about this?
h f = f (1::Int) == (2::Int)
Can I apply f to a function of type Int->Double? If no, then it's a
pity, because I could inline it (the comparison would be done on Doubles).
If yes, then what is the inferred type for h? Note that Int->Double is not
a subtype of Int->Int, so if h :: (Int->Int)->Bool, then I can't imagine
how h can be applied to something :: Int->Double.
--
Marcin 'Qrczak' Kowalczyk