[Haskell-beginners] Help with types
Thomas Davie
tom.davie at gmail.com
Thu Apr 23 10:17:07 EDT 2009
On 23 Apr 2009, at 15:52, Daniel Carrera wrote:
> Daniel Fischer wrote:
>> Try explicitly converting the length to the appropriate type:
>> average xs = sum xs / fromIntegral (length xs)
>
> Thanks. Could you help me understand what's happening?
>
> 1. length returns Int.
> 2. sum returns Num.
> 3. (/) wants Fractional.
>
> It looks like (/) is happy with Num but doesn't like Int. This
> surprises me. I would have thought that Fractional is a kind of Num
> and Int is a kind of Fractional
Int isn't a Fractional because it can't represent fractional numbers.
Bob
More information about the Beginners
mailing list