So, since we've decided to postpone meeting (get better soon, y'all <3),
I have an opportunity to bring up a more interesting Reader exercise:
Write an evaluation function for the following data type:
data Arith =
Const Int
| Var String
| Negate Arith
| Plus Arith Arith
| Times Arith Arith
type Env = ???
eval :: Arith -> Reader Env Int
eval = ???
-- Example
ex = let x = Var "x"
in (x `Times` x) `Plus` ((Const 2) `Times` x) `Plus` (Const 1)
environment = ???
ex_value = run (eval ex) environment -- e.g., if x=3 in your
environment, then ex_value=16.
It might also be instructive to write eval without using Reader to see
what the differences are. (Or you could check my github where there is a
reader-free version of something similar...)
--ℕ
On 3/10/19 5:46 PM, Linux Mercedes wrote: