Hacker News new | ask | show | jobs
by sfvisser 5534 days ago
When you've worked with Haskell a bit this code is actually very readable. Admittedly some experience is required.

With a two named helper functions and a bit of additional alignment everyone that has ever written a parser before in Haskell immediately recognizes the structure, thanks to use of applicative functor syntax (<|> and <$>):

    value :: Parser Value
    value =  List   <$> parenthesis (sepBy value (takeWhile1 isSpace_w8))
         <|> Number <$> parseNumber
         <|> Symbol <$> takeWhile1 (inClass "A-Za-z\\-")
    
      where parenthesis p = char8 '(' *> p <* char8 ')'
            parseNumber   = fst . fromJust . B.readInteger <$> takeWhile1 isDigit_w8