[Haskell-cafe] Can't explain this error

robert dockins robdockins at fastmail.fm
Mon Jul 11 12:07:56 EDT 2005


You are trying to divide by an Integer and get a Float.  Haskell doesn't 
do automatic numeric conversion, so you have to do the casts manually.

Prelude> let sumHam n = sum [ 1 / (fromIntegral x) | x <- [1..n] ]
Prelude> sumHam 5
2.283333333333333


Dinh Tien Tuan Anh wrote:
> 
>  could anyone tell me what i did wrong with this please
> 
> sumHam :: Integer -> Float
> sumHam n = sum [1/x | x<-[1..n]]
> 
> Error: type error in explicitly typed binding
> **** Term:                 sumHam
> **** Type:                  Integer -> Integer
> **** Does not match : Integer -> Float
> 
> 
> 
> 
> it only works if i remove the first line. Tried changing Float by Double 
> and still not working
> 
> Pls help
> Cheers
> 
> _________________________________________________________________
> Be the first to hear what's new at MSN - sign up to our free 
> newsletters! http://www.msn.co.uk/newsletters
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list