[Haskell-beginners] Strange gchi behavior?
Brandon Allbery
allbery.b at gmail.com
Thu Mar 15 05:45:41 CET 2012
On Thu, Mar 15, 2012 at 00:28, Olwe Melwasul <galaxybeingplan9 at gmail.com>wrote:
> I'm working my way through Real World Haskell and am in Chapter 3. On page
> 56 there is a discussion called "Record Syntax" and it gives this data
> constructor:
>
> data Customer = Customer {
> customerID :: CustomerID
> , customerName :: String
> , customerAddress :: Address
> } deriving (Show)
>
> where CustomerID and Address were defined (and loaded) before. But when I
> try to put in data, I get these errors
>
> *Main> :load BookStore.hs
> [1 of 1] Compiling Main ( BookStore.hs, interpreted )
> Ok, modules loaded: Main.
> *Main> customer1 = Customer 271828 "J.R. Hacker"
>
You cannot create a binding that way in ghci; you need to use a "let", or
for monadic bindings "<-". (Think of the ghci prompt as being inside a big
"do" block, although in more recent versions of GHC there are various top
level things that will work.)
*Mail> let customer1 = Customer 271828 "J. R. Hacker." ["255 Syntax Ct",
"Milpitas, CA 95134",
"USA"]
Note the "let".
(Summary: ghci is not the top level of a source file. I'm surprised you
didn't get an error if you tried to do the data declaration in your other
example, unless you were using 7.4.1 where "data" works but a binding
without "let" or "<-" still does not.)
--
brandon s allbery allbery.b at gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120315/6c480c6d/attachment-0001.htm>
More information about the Beginners
mailing list