[Haskell-cafe] Signature of a function

robert dockins robdockins at fastmail.fm
Tue Jan 11 10:02:20 EST 2005

Dmitri Pissarenko wrote:
> Hello!
> I have a function activityIndicator, which has an argument of class Customer
> and should return a numeric value.
> The module is defined as follows.
> <module-definition>
> data Purchase = Purchase { price, rebate :: Double }
>         deriving (Show, Eq)
> data Customer = Customer { id :: Int, purchases :: [Purchase] }
> activityIndicator :: Customer -> Num
> activityIndicator (Customer id purchases) = length purchases
> </module-definition>

> What is wrong in the signature above?

'Num' is not a type.  It is a type class.  You can think of it as a set 
of types; it includes, for example, Int, Float and the other usual 
suspects.  If you want a type in the class Num the signature looks 
something like this:

Num a => a

Which reads like "the type a, where a is in the class Num"

However, the problem here is that length returns an Int; so your 
signature should be:

activityIndicator :: Customer -> Int

More information about the Haskell-Cafe mailing list