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

John Goerzen jgoerzen at complete.org
Mon Jun 27 15:50:59 EDT 2005


On 2005-06-27, Mads Lindstrøm <mads_lindstroem at yahoo.dk> wrote:
> Hi John
>
>> test :: forall a. (Num a) => a
>> test = 2 * 5 + 3

[ snip ]

> 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:
>

If you omit it, the compiler will decide that test is some arbitrary
type (Double, Integer, whatever).  While rpnShow, etc. will still work,
they will not show you the same thing, since the compiler will have
already "optimized" the expression down to one set type.

Which compiler or interpreter are you using?

> 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.

Note that test in this example is not a function.

-- John



More information about the Haskell-Cafe mailing list