Since expressions can read and write to the storage area, your evaluation function should receive the memory state as a parameter and return the new state to the result.
evaluate :: Expr -> Int -> (Float, Int)
[where Int is the storage type and Float is the result type, of course you can change that.)
When implementing evaluate (Sum ab) you need to pass the memory to evaluate a , get the new memory value and pass it evaluate b .
| | m \ / |----------| x |evaluate a|--------| |----------- | | | | m' | \ / \ / |----------| y --- |evaluate b|----->| + | |----------| --- | | | | \ / \ / final final value of result memory
Use pattern matching. You start with let (x,m') = evaluate am in ...
sdcvvc
source share