[Haskell-cafe] Why I Love Haskell In One Simple Example

Mads Lindstrøm mads_lindstroem at yahoo.dk
Mon Jun 27 15:22:59 EDT 2005

Hi John

> Also, I defined this in my source file:
> test :: forall a. (Num a) => a
> test = 2 * 5 + 3
> Now, it can be used:
> NumTest> test
> 13
> NumTest> rpnShow test
> "2 5 * 3 +"
> NumTest> prettyShow test
> "(2*5)+3"
> NumTest> test + 5
> 18

I had newer seen anybody use "forall a." in function signatures before,
and therefore was curious about its effect. This is probably do to my
inexperience regarding Haskell. However, I tried to remove it and wrote
this instead:

test :: (Num a) => a

and the code still compiled and seems to run fine. Also using the
prettyShow and rpnShow functions. So, why are you using the forall
keyword? (this is not meant as a critique, i am just curious)

I tried to find documentation about the use of the forall keyword in
respect to functions (I do know about it in with respect to
existentially quantified types), but with no luck. So, if anybody has
some good pointers, please let med know about it.

/Mads Lindstrøm

More information about the Haskell-Cafe mailing list