[Haskell-beginners] Strange gchi behavior?

David McBride toad3k at gmail.com
Thu Mar 15 05:39:39 CET 2012


There's nothing wrong with the Customer data type.  More than likely
you have a white space error on some lines before the Customer
datatype, or perhaps a missing closing bracket on some previous data
type.  Make sure there are no hard tabs, only spaces.

If you plan to do mulitline input in ghci, you must go :{\n before you
start, :}\n to end.  You can find this in :help in ghci if you forget
what it was.

But that is not why your customer = ... line does not work.  When you
declare something like that in ghci, you must use let, ie "let
customer = undefined".  You don't have to do that in the file, but
ghci is already running, it requires let for new bindings.  I'm not
sure why, but it is not too big of a deal once you realize it.

On Thu, Mar 15, 2012 at 12:28 AM, 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"
>             ["255 Syntax Ct",
>              "Milpitas, CA 95134",
>              "USA"]
>
> <interactive>:1:11: parse error on input `='
> *Main>
> <interactive>:1:18: parse error (possibly incorrect indentation)
> *Main>
> <interactive>:1:21: parse error on input `,'
> *Main>
> <interactive>:1:6: parse error on input `]'
> *Main>
>
> If I put the whole data add on one line, I still get
>
> *Main> customer1 = Customer 271828 "J.R. Hacker" ["255 Syntax Ct",
> "Milpitas, CA 95134", "USA"]
>
> <interactive>:1:11: parse error on input `='
> *Main>
>
> I'm on Ubuntu 11.10, using Emacs23, haskell-mode, running 7.0.4. Any ideas
> what's going wrong? The book gives this alternate version:
>
> data Customer = Customer Int String [String]
>                 deriving (Show)
>
> customerID :: Customer -> Int
> customerID (Customer id _ _) = id
>
> customerName :: Customer -> String
> customerName (Customer _ name _) = name
>
> customerAddress :: Customer -> [String]
> customerAddress (Customer _ _ address) = address
>
> ...but it produces the same errors.
>
>
> Olwe
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list