Tutorial by Examples

λ> :t 1 1 :: Num t => t λ> :t pi pi :: Floating a => a In the examples above, the type-checker infers a type-class rather than a concrete type for the two constants. In Haskell, the Num class is the most general numerical one (since it encompasses integers and reals), but pi must...
The error message in the title is a common beginner mistake. Let's see how it arises and how to fix it. Suppose we need to compute the average value of a list of numbers; the following declaration would seem to do it, but it wouldn't compile: averageOfList ll = sum ll / length ll The problem is...
What's the type of (+) ? λ> :t (+) (+) :: Num a => a -> a -> a What's the type of sqrt ? λ> :t sqrt sqrt :: Floating a => a -> a What's the type of sqrt . fromIntegral ? sqrt . fromIntegral :: (Integral a, Floating c) => a -> c

Page 1 of 1