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
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to