Skip to content

Instantly share code, notes, and snippets.

@tarnacious
Created September 30, 2013 13:49
Show Gist options
  • Save tarnacious/6764089 to your computer and use it in GitHub Desktop.
Save tarnacious/6764089 to your computer and use it in GitHub Desktop.
While writing the same parser in JavaScript and Haskell I found these two snippets illustrated to me why monads and do syntax are awesome.
piece :: Parser Piece
piece = do
many space
t <- pieceType
c <- pieceColour
return $ Piece t c
piece = _do(many(space), function(_) {
return _do(pieceType, function(t) {
return _do(colour, function(c) {
return ret(new Piece(t,c));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment