type of (/) ?

Christian Maeder maeder at tzi.de
Tue Dec 9 17:44:53 EST 2003


Yaroslav Korchevsky wrote:
> my_avg list =  (accum list) / (length list)
> ================================

> 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"?

(/) expects two equally typed arguments
and (length list) yields the type Int.

> When I try to replace (length list) with number - it works.
>  
> ================================
> my_avg list =  (accum list) / 5 --works fine
> ================================
> xx = 5
> my_avg list =  (accum list) / xx --doesn't work
> -- same message as above

Try to check the type of 5 and xx using ":t" at the hugs prompt.

> Possibly, I don't know something important, or Hugs is not quite mature?

Haskell does at least allow literal numbers to fit several types.

HTH Christian

P.S. fromIntegral can be used for conversions



More information about the Haskell-Cafe mailing list