I\'ve recently picked up Haskell at uni and I\'m working my way through a set of exercises, here\'s a snippet of one that I can\'t make sense of:
\"Consider the followin
Years ago, I got clever, and I declared my AST type an instance
of Num
, Eq
and Ord
, then defined the mathematical and comparison operators for AST expressions, so that expr1 + expr2
would yield a valid AST. Using sevenj’s declarations, this would be written like (+) x y = Sum x y
, where the right-hand side is the constructor of an AST expression. For brevity, one = Lit One
and two = Lit Two
. Then you might write one + one == two
and the operators would generate your AST with the correct precedence. Between that and abuse of the let { ... } in ...
syntax to allow for arbitrary indentation, I had a way to write ASTs that was almost just the toy imperative language itself, with some boilerplate above, below and on the left.
The TA grading my assignment, though, was not amused, and wrote, “This is not Haskell!”