[Haskell-beginners] Type Class Instance Question

Michael Orlitzky michael at orlitzky.com
Fri Feb 21 05:02:10 UTC 2014


On 02/20/2014 11:48 PM, Philippe Sismondi wrote:
> In the Haskell 98 and 2010 reports it states that one may declare
> something of the form /(tyvar1 -> tyvar2)/ to be an instance of a type
> class. Is that a function or what is it? Can anyone point me to an
> example of this?

It refers to something like (a -> b) which is the type of functions from
'a' to 'b' (tyvar1 and tyvar2 in the report). Here's a
not-terribly-useful example of such an instance:

  instance Show (a -> b) where
    show f = "some kinda function"

  main = print foldl

A better example could make those functions an instance of Num, so that
you could write f + g to represent f(x) + g(x), f * g for f(x) * g(x),
and so on.




More information about the Beginners mailing list