[Haskell-cafe] a newbie's question
robert dockins
robdockins at fastmail.fm
Thu Apr 21 11:14:22 EDT 2005
>> Hi,
>>
>> I'm beginning to study Haskell, For the following
>>
>> a = [1,2,3]
>>
>> b = "there"
>>
>>
>> do x <- a
>>
>> y <- b
>>
>> return (x , y)
>>
>> Winhugs cannot run it. Gives
>>
>> Syntax error in input (unexpected backslash (
>> lambda))
>
> Your problem is that you're using monads to grab the contents of a and
> b, while a and b are not monadic...
They *are* actually monadic, just perhaps not the monad the OP expects.
This code should compile and produce the cartesian product of the
numbers {1, 2, 3} and the characters {t,h,e,r,e}. I'm not sure what
would cause the given error -- it may be a layout problem (the indention
is wrong but it might just be the mailer).
___ ___ _
/ _ \ /\ /\/ __(_)
/ /_\// /_/ / / | | GHC Interactive, version 6.2.2, for Haskell 98.
/ /_\\/ __ / /___| | http://www.haskell.org/ghc/
\____/\/ /_/\____/|_| Type :? for help.
Loading package base ... linking ... done.
Prelude> let a = [1,2,3]
Prelude> let b = "there"
Prelude> do { x <- a; y <- b; return (x,y) }
[(1,'t'),(1,'h'),(1,'e'),(1,'r'),(1,'e'),(2,'t'),(2,'h'),(2,'e'),(2,'r'),(2,'e')
,(3,'t'),(3,'h'),(3,'e'),(3,'r'),(3,'e')]
Prelude>
More information about the Haskell-Cafe
mailing list