Haskell newbie here, trying to write code to parse math expressions. Code:
isDigit :: Char -> Bool
isDigit c = c >= \'0\' && c <= \'9\'
pars
No, but you can use cases if you'd like:
parseNumber :: String -> Maybe (String, String)
parseNumber [] = Just ("", "")
parseNumber (h:ls)
| isDigit h =
case () of
() | p == Nothing -> Just([h], ls)
| otherwise -> Just (h:fst d, snd d) -- Ends in a digit
| h == '.' =
case () of
() | p == Nothing -> Nothing
| not ('.' `elem` (snd d)) -> Just (h:(fst d), snd d)
| otherwise = Nothing
where
p = parseNumber ls
Just d = parseNumber ls
Alternatively, multiway if works in a similar manner (if True | p1 -> b ; | p2 -> c).