[Haskell-beginners] main

Brent Yorgey byorgey at seas.upenn.edu
Sat Oct 3 16:27:13 EDT 2009

On Sat, Oct 03, 2009 at 08:07:50PM +0100, John Moore wrote:
> Hi, 
>     I must be doing something wrong when I run a program it comes up on the
> screen as OK module loaded Main
> *Main>
> But it will not do what I program to do. What do I enter after *main> I
> tried putting in the arguments but ot just returns the arguments.
> For example:
> signum x | x < 0 = -1
> 	  | x == 0 = 0
>               | x > 0 = 1

If you have the above in a file and load it into ghci, it just means
that now the function 'signum' is available for use.  You type
expressions at the ghci prompt, so if you type 5 by itself, that is
just the expression 5, which of course has the value... 5. =) If you
want to evaluate signum with an input you must type, for example,

  signum 5

However, I should warn you that the Haskell Prelude already defines a
function called 'signum', so if you load the above and type 'signum 5'
it will give you an error about signum being ambiguous (it does not
know which one you want, the one from the Prelude or the one you
defined in the file you loaded).  There are various ways around this,
but the easiest for now is probably just to use a different name for
your function.


More information about the Beginners mailing list