Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declarations at the GHCi prompt

I have just installed Haskell Platform for Windows (version 2011.2.0.1), and started to work through the HaskellQuestions.pdf

The second question requires "x = 3" as the answer. But when I enter this into GHCi I get

GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> x = 3

<interactive>:1:3: parse error on input `='
Prelude>

Why? I checked the answer, and I am right. Whats the matter with the equals sign?

like image 586
Ian Avatar asked May 25 '11 20:05

Ian


1 Answers

In GHCi, to assign a value, you have to go

let x = 3

In regular Haskell code, x = 3 would be valid (see NB below).

Real World Haskell's Getting Started page has lots of useful info about using GHCI.

You can also look at the documentation for GHCi (but personally, I find Real World Haskell a little more digestable).

N.B. As EdvardM notes in the comments, the syntax for using let in this context is from Haskell's do notation (if you're just beginning, don't stress yourself out if you're a little lost. Take your time, have fun, and it ought to make sense in no time).

like image 63
Zach L Avatar answered Sep 28 '22 09:09

Zach L