[Haskell-cafe] Multiple statements with Where

Tillmann Rendel rendel at rbg.informatik.tu-darmstadt.de
Tue Dec 18 09:16:49 EST 2007


insertjokehere wrote:
> --A parser for recognising binary operations
> parseBinaryOp :: String -> String -> [(Expr, Expr, String)]
> parseBinaryOp op str
> 	| (elem op binops) && (notElem '(' (snd bm)) && (notElem ')' (snd bm)) &&
> (elem nstr!!1 binops) = [(EInt 1, EInt 1, "HERE!")]

You want (elem (nstr !! 1) binops) here because function application 
binds stronger then all operators. You can even write

   elem op binops && notElem '(' (snd bm) && ...

for that reason.

> 	| otherwise = []
> 		where bm = bracketMatch str
> 			  nstr = words (snd (bracketMatch str))

You want

   where bm = ...
         nstr = ...

here, because the first non-space characters of lines belonging to the 
same layout-block have to be at the same horizontal position. Your

   where bm = bracketMatch ...
             nstr = ...

is parsed as

   where { bm = bracketMatch ... nstr = ... }

instead of

   where { bm = bracketMatch ...;
           nstr = ... }

Tillmann


More information about the Haskell-Cafe mailing list