4 ms·
Here's the same thing in Haskell, using Parsec stmt = fmap (++ ";") expr expr = call <|> lit call = fmap (\(fn:args) -> fn ++ "(" ++ int
by jhpriestley 11y ago
Here's the same thing in Haskell, using Parsec
stmt = fmap (++ ";") expr
expr = call <|> lit
call = fmap
(\(fn:args) -> fn ++ "(" ++ intercalate "," args ++ ")")
(between (str "(" >> spaces) (str ")" >> spaces) (many1 expr))
lit = (many1 digit <|> many1 letter) <* spaces
- jakub_h 11y agoWith enough libraries, everything fits into a few lines. How big is Parsec itself?
- LewisJEllis 11y agoThe answer to your question is "Not really that big": 3.5kloc with comments/whitespace and 1.6kloc without. Your point is valid that much of this is the library's doing, but I think more of the difference than you're letting on is just from how well-suited functional languages are to this sort of work compared to dynamic scripting languages. Parsec is practically a Haskell standard library, anyway; I wouldn't discount it any more than I would discount using Node's buffer or stream module.
- mej10 11y agoI think you could implement (naively) all of the Parsec functionality used in the comment in like ~30 lines.