[Haskell-beginners] prefix instead of infix

John Moore john.moore54 at gmail.com
Sun Jan 10 14:33:40 EST 2010


Hi,
   Can anyone explain how to turn the code from infix to Prefix. I want to
include a let statement below. I not sure of how prefix  works.

expr :: Parser Expr
expr = buildExpressionParser table factor
   <?> "expression"
table :: [[Operator Char st Expr]]
table = [[op "*" Mul AssocLeft, op "/" Div AssocLeft]
       ,[op "+" Add AssocLeft, op "-" Sub AssocLeft]
       ]
 where
   op s f assoc
      = Infix (do{ string s; return f}) assoc
factor :: Parser Expr
factor = do{ char '('
          ; x <- expr
          ; char ')'
          ; return x
          }
     <|> number
     <?> "simple expression"
number :: Parser Expr
number = do{ ds <- many1 alphaNum
          ; return (Val $ read ds)
          }

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100110/ccb4b7a6/attachment.html


More information about the Beginners mailing list