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

Mads Lindstrøm mads_lindstroem at yahoo.dk
Mon Jun 27 16:12:38 EDT 2005


Hi John Goerzen

> 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.
They show the same thing on my computer, namely

"2 5 * 3 +"

if I do ":type test" I get (with or without the forall a.):

rpnShow :: Num a => SymbolicManip a -> String

> 
> Which compiler or interpreter are you using?
hugs -98

:version
-- Hugs Version November 2003

I have not tried with ghc(i), as it would not load MissingH.Str. Some
problem I will have to look into later.

> 
> > 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.
OK, I assumed it was, as I thought all functions started with lower case
and all modules, classes, and data/type constructors started with upper
case. It does not take any variables as input, but that is still a
function in my book (but I could be wrong there. I am no mathematician).

> 
> -- John
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 

note that I am not using:

test :: a  -- this will actually not compile

or not giving any type signatur, but using:

test :: (Num a) => a

/Mads Lindstrøm




More information about the Haskell-Cafe mailing list