Hacker News new | ask | show | jobs
by jxxcarlson 2855 days ago
One more point. Writing something like the MiniLatex parser would be somewhere between impossible altogether and nightmarish without an expressive type system. Below is the definition of the type of the abstract syntax tree (AST) for MiniLatex. Just eleven lines of code. Yes, I know. No typeclasses in Elm. But Elm's type system is surprisingly expressive, and with it one can do some rather sophisticated work. I've been very happy with it.

    type LatexExpression
        = LXString String
        | Comment String
        | Item LatexExpression
        | InlineMath String
        | DisplayMath String
        | SMacro String (List LatexExpression) (List LatexExpression) LatexExpression 
        | Macro String (List LatexExpression) (List LatexExpression) 
        | Environment String (List LatexExpression) LatexExpression 
        | LatexList (List LatexExpression)
        | LXError (List DeadEnd)