
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))

On Apr 21, 2005, at 3:47 PM, SCOTT J. wrote:
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... You probably if you're only just setting out don't want to pay attention to any of the do notation or monadic code. To get the result it looks like you want, all you need to do is this: (a, b) you can then define this as a new constant: c = (a, b)
Hope that helps Bob

Thomas Davie wrote:
On Apr 21, 2005, at 3:47 PM, SCOTT J. wrote:
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... You probably if you're only just setting out don't want to pay attention to any of the do notation or monadic code. To get the result it looks like you want, all you need to do is this: (a, b) you can then define this as a new constant: c = (a, b) Hope that helps Bob
On the other hand, perhaps he wanted all possible combinations of values in the lists a and b. Since a list is a monad, this, for example, works fine: a = [1,2,3] b = "there" abs = do x <- a y <- b return (x,y) In Hugs: abs ==> [(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')] -Paul

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>

You forgot to bind a name to your do-expression. Try: foo = do x <- a y <- b return (x,y) On Thu, 21 Apr 2005, SCOTT J. wrote: ] 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)) -- Tom Harke Ph.D. Student Computer Science Portland State University
participants (5)
-
Paul Hudak
-
robert dockins
-
SCOTT J.
-
Thomas Davie
-
Tom Harke