Pattern matching! I've only been familiar with variable unpacking from Python and then I learned some Erlang. Many people don't like Erlang's syntax but pattern matching is great! I understand that F# and OCaml also have that.
Haskell types. I've been toying with language construction lately and it's very nice.
data Exp
= Let String Exp Exp
| Exp1 Exp1
deriving Show
data Exp1
= Plus Exp1 Term
| Minus Exp1 Term
| Term Term
deriving Show
data Term
= Times Term Factor
| Div Term Factor
| Factor Factor
deriving Show
data Factor
= Int Int
| Var String
| Brack Exp
deriving Show
This would take an entire class hierarchy in Java.
Wait, so you can write an entire language grammar in Haskell like that?! I once wrote a compiler in java, and I ended up just using ANTLR to generate the syntax tree (and a huge string of If statements to clean up that tree). This would have been a lot more fun to work with.
I understand you can do the same in OCaml and F#, they say ML languages are well suited for compiler construction for that. I've been playing with yacc-like Java parser generators and that seems such a time saver compared to a Java class hierarchy.
Edit: you still have to define production rules though, just like in Yacc.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Pattern matching! I've only been familiar with variable unpacking from Python and then I learned some Erlang. Many people don't like Erlang's syntax but pattern matching is great! I understand that F# and OCaml also have that.
Haskell types. I've been toying with language construction lately and it's very nice.
This would take an entire class hierarchy in Java.
And third, string interpolation is very handy.
Wait, so you can write an entire language grammar in Haskell like that?! I once wrote a compiler in java, and I ended up just using ANTLR to generate the syntax tree (and a huge string of If statements to clean up that tree). This would have been a lot more fun to work with.
Yes it's from the parser generator example
haskell.org/happy/doc/html/sec-usi...
I understand you can do the same in OCaml and F#, they say ML languages are well suited for compiler construction for that. I've been playing with yacc-like Java parser generators and that seems such a time saver compared to a Java class hierarchy.
Edit: you still have to define production rules though, just like in Yacc.