[Haskell-cafe] simple parsing
satorisanitarium
satorisanitarium at gmail.com
Tue Oct 27 18:38:21 EDT 2009
I'm trying to parse a list of numbers plus four diferent signs (+-*/)
in this way:
Lets say the list is "32+5/46" result would be "2+5/4"
I get:
"2+5/4*** Exception: geneticSimple.hs:(55,0)-(65,35): Non-exhaustive
patterns in function chromoResult
If the list is "32+5**6" result would be "2+5*6"
I get:
"2+5/*** Exception: geneticSimple.hs:(55,0)-(65,35): Non-exhaustive
patterns in function chromoResult
If the list is "32+-72" resoult would be "2+7"
I get:
"2+*** Exception: geneticSimple.hs:(55,0)-(65,35): Non-exhaustive
patterns in function chromoResult
code:
chromoResult [] = []
chromoResult (a:b:c:xs)
| elem a "0123456789" && elem b "0123456789" && elem c "0123456789" =
chromoResult (c:xs)
| elem a "0123456789" && elem b "0123456789" && elem c "+-*/" = b:c:
chromoResult xs
| elem a "0123456789" && elem b "+-*/" && elem c "0123456789" =
a:b:c : chromoResult xs
| elem a "0123456789" && elem b "+-*/" && elem c "+-*/" = a:b :
chromoResult (c:xs)
| elem a "+-*/" && elem b "0123456789" && elem c "0123456789" =
chromoResult (b:c:xs)
| elem a "+-*/" && elem b "0123456789" && elem c "+-*/" = b:c :
chromoResult xs
| elem a "+-*/" && elem b "+-*/" && elem c "0123456789" =
chromoResult (c:xs)
| elem a "+-*/" && elem b "+-*/" && elem c "+-*/" = chromoResult xs
| otherwise = chromoResult (b:c:xs)
I suspect my approach is flawed but i have exausted my ideas.
I need a fresh approach so if anybody would be kind enough and just
give me a hint how to approach the problem.
Thx in advance.
More information about the Haskell-Cafe
mailing list