Hacker News new | past | comments | ask | show | jobs | submit login

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



With enough libraries, everything fits into a few lines. How big is Parsec itself?


The 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.


I think you could implement (naively) all of the Parsec functionality used in the comment in like ~30 lines.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: