[Haskell-cafe] Multiple statements with Where

Jules Bean jules at jellybean.co.uk
Tue Dec 18 09:10:16 EST 2007


insertjokehere wrote:
> Hi all, I am having problems adding multiple definitions with where for
> example in my code
> 
> --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!")]
> 	| otherwise = []
> 		where bm = bracketMatch str
> 			  nstr = words (snd (bracketMatch str))

alignment. Where clauses are layout.

Here is how I suggest you layit out:

--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!")]
     | otherwise = []
   where bm = bracketMatch str
         nstr = words (snd (bracketMatch str))


Note that the where clause comes to the left of the |, because where 
clauses scope over all the guards

It may be a good idea not to use 'hard' tabs.

Jules


More information about the Haskell-Cafe mailing list