[Haskell-cafe] Confusing type specialisation in ghci

David Carter dmc at sanger.ac.uk
Fri Oct 5 11:45:07 EDT 2007


Can someone elucidate to me this behaviour from ghci 6.6.1? Why is the 
type of sqlist specialised to Integer?

Prelude> let sq x = x * x
Prelude> :t sq
sq :: (Num a) => a -> a
Prelude> sq 2.5
Prelude> :t map sq
map sq :: (Num a) => [a] -> [a]
Prelude> map sq [2.5]

This is all as I would expect so far, but:

Prelude> let sqlist = map sq
Prelude> :t sqlist
sqlist :: [Integer] -> [Integer]

And indeed, I get

Prelude> sqlist [2.5]

    No instance for (Fractional Integer)
    ... etc



 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 

More information about the Haskell-Cafe mailing list