[Haskell-beginners] Noob question.(I'm trying 'http://learnyouahaskell.com' tutorial)

Kyle Murphy orclev at gmail.com
Tue Apr 17 00:39:16 CEST 2012

As aditya pointed out, you need to declare any function you use (or provide
a type signature of) but don't explicitly define as undefined. That will
allow the code to compile but will throw an error when any undefined
functions are called.

I want to address what Jakub said however as I think it's somewhat

On Mon, Apr 16, 2012 at 17:55, Jakub Oboza <jakub.oboza at gmail.com> wrote:
> Because GHC is limited
> in GHC you cant do
> double a = a * a
> you have to put into let
> like this
> let double a = a * a
> Cheers!

It might be more accurate to say that GHCi (the interactive shell, not GHC
the compiler) makes some assumptions about what you're typing in order to
make it more useful. For example, GHCi assumes that you're always typing
something of the form:

IO a

This is why you need to change most "normal" haskell expressions into let
bindings, because then you're explicitly telling GHCi that you don't want
to interpret what you're typing as an IO expression. The reason it makes
that assumption is because often times you really do want it interpreted as
IO as in the example:

ghci> putStrLn $ "Example " ++ show 5
Example 5

It also makes assumptions about types of constants that GHC normally does
not. Furthermore it allows rebinding of declarations as in:

ghci> let x = 5
ghci> x
ghci> let x = 6
ghci> x

You need to be careful with that though because something like this will
not behave as you might expect:

ghci> let x = 5
ghci> let f = x * x
ghci> f
ghci> let x = 10
ghci> f

GHCi is very powerful and a great way to experiment and test code out, but
it's important to understand some of the assumptions it makes in order to
be more productive in the majority of cases. On Linux it's often best to
start with an empty hs file, load that into GHCi, and then use :edit to
open it in an editor and fill the contents out. You can then save and exit
your editor and it will return you to the GHCi prompt where you can
experiment and inspect the code you've written.

-R. Kyle Murphy
Curiosity was framed, Ignorance killed the cat.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120416/79062b89/attachment.htm>

More information about the Beginners mailing list