type of (/) ?

Hal Daume III hdaume at ISI.EDU
Tue Dec 9 08:29:32 EST 2003


> ERROR "U:\slav\FP\Avg.hs":11 - Type error in application
> *** Expression     : accum list / length list
> *** Term           : accum list
> *** Type           : Float
> *** Does not match : Int
>  
> Why "accum list" should match to "Int"?
> When I try to replace (length list) with number - it works.

length :: [a] -> Int   -- this is your problem

use genericLength :: Num k => [a] -> k instead

> ================================
> my_avg list =  (accum list) / 5 --works fine
> ================================

This works because '5' is translated to 'fromInteger 5', which can be a 
Float as desired.

> xx = 5
> my_avg list =  (accum list) / xx --doesn't work
> -- same message as above

This doesn't work because defaulting occurs and xx is given type Integer.

-- 
 Hal Daume III                                   | hdaume at isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume



More information about the Haskell-Cafe mailing list