Re: [Haskell-cafe] Parser problem continued

2005-03-15 Thread robert dockins

expr :: Parser Int
expr = do t - term
  do symbol +
 e - expr
 return e
  return (t + e)
   +++ return t- 
't' is not in scope at the arrow.  t only exists inside the
do block, and your code parses like this
( do t -  return (t+e) ) +++ ( return t )
perhaps like this:
expr = do t - term
  (do symbol +
  e - expr
  return (t+e)
  )
  +++
  (return t)
although I think you may also want a 'try' before the first alternative.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Parser problem continued

2005-03-15 Thread Nicola Whitehead
perhaps like this:

 expr = do t - term
   (do symbol +
   e - expr
   return (t+e)
   )
   +++
   (return t)


although I think you may also want a 'try' before the first alternative.

No, that still gives the same undefined variable error. :(

Nik

Dr Nik Freydís Whitehead
University of Akureyri, Iceland
*
Having the moral high ground is good.
Having the moral high ground and an FGMP-15 is better.
*

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parser problem continued

2005-03-15 Thread Tomasz Zielonka
On Tue, Mar 15, 2005 at 03:44:55PM -, Nicola Whitehead wrote:
 perhaps like this:
 
  expr = do t - term
(do symbol +
e - expr
return (t+e)
)
+++
(return t)
 
 although I think you may also want a 'try' before the first alternative.
 
 No, that still gives the same undefined variable error. :(

Sometimes I prefer to write such code in a lispy way:

expr = do t - term
  ((+++)
  (do symbol +
  e - expr
  return (t+e))
  (return t))

Best regards
Tomasz
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parser problem continued

2005-03-15 Thread Arthur Baars
The layout of your code is very important when writing haskell code:
Your code :
expr = do t - term
  do symbol +
 e - expr
 return e
  return (t + e)
   +++ return t
is equivalent to:
expr = do { t - term
  ; do { symbol +
   ; e - expr
   ; return e
   }
  ; return (t + e) -- e is not in scope
  }
   +++ return t -- t is not in scope
Both t and e are not in scope:
* e is in a nested do-block
* the expression 'return t' is outside the do-block
What you probably mean is:
expr = do t - term
  do symbol +
 e - expr
 return (t + e)
 +++ return t
which is equivalent to:
expr = do { t - term
  ; do { symbol +
   ; e - expr -- (dropped the return e line)
   ; return (t + e)
   }
   +++ return t
  }
Now t and e are in scope. The parser 'expr' will first recognize a 
'term' and then try to recognize a '+' symbol followed by an 
expression. If that fails it returns 't'.

Cheers,
Arthur
On 15-mrt-05, at 16:28, Nicola Whitehead wrote:
Curiouser and curiouser...
 
expr :: Parser Int
expr = do t - term
  do symbol +
 e - expr
  return (t + e)
   +++ return t
solves the undefined variable problem but introduces a new 'Last 
operator in do {...} must be an expression' error, which then 
disappears if I explicitly return e
 
expr :: Parser Int
expr = do t - term
  do symbol +
 e - expr
     return e
  return (t + e)
   +++ return t

to give me the original undefined variable t error at the line expr = 
do t - term . It looks in scope to me... :(
 
Thanks,
 
Nik
 
Dr Nik Freydís Whitehead
University of Akureyri, Iceland
*
Having the moral high ground is good.
Having the moral high ground and an FGMP-15 is better.
*
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Parser problem continued

2005-03-15 Thread Nicola Whitehead
Thanks folks!

Writing it in a lispy manner seems to work. I see what Arthur means about the 
layout - I think I'm still thinking too much in C. :)

Nik

Dr Nik Freydís Whitehead
University of Akureyri, Iceland
*
Having the moral high ground is good.
Having the moral high ground and an FGMP-15 is better.
*

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe