module Main where
-- Integer arithmetic with (+) and (/)
data Term =
| Plus Term Term
| Div Term Term
--
-- Basic evaluator
--
eval ( N n) = n
eval ( Plus t1 t2) = eval t1 + eval t2
eval
( Div t1 t2
) = eval t1 `
div ` eval t2
--
-- Evaluator that counts the number of operations
--
inc n = n + 1
evalWithCount
:: Term
-> ( Int , Int ) evalWithCount t = eval' (0, t)
where
eval' = undefined
-- The exercise works best if you only use "inc" to bump the accumulator
--
-- Evaluator that catches division by zero
--
-- Returns (Ok n) in case of success
-- Returns (Error "Division by zero") otherwise
--
data Result a = Error String | Ok a
evalChecked :: Term -> Result Int
evalChecked = undefined
main = print (undefined::String)
bW9kdWxlIE1haW4gd2hlcmUKCi0tIEludGVnZXIgYXJpdGhtZXRpYyB3aXRoICgrKSBhbmQgKC8pCmRhdGEgVGVybSA9IAogICAgICBOIEludAogICAgfCBQbHVzIFRlcm0gVGVybQogICAgfCBEaXYgVGVybSBUZXJtCgotLQotLSBCYXNpYyBldmFsdWF0b3IKLS0KCmV2YWwgOjogVGVybSAtPiBJbnQKZXZhbCAoTiBuKSA9IG4KZXZhbCAoUGx1cyB0MSB0MikgPSBldmFsIHQxICsgICAgIGV2YWwgdDIKZXZhbCAoRGl2IHQxIHQyKSAgPSBldmFsIHQxIGBkaXZgIGV2YWwgdDIKCi0tCi0tIEV2YWx1YXRvciB0aGF0IGNvdW50cyB0aGUgbnVtYmVyIG9mIG9wZXJhdGlvbnMKLS0KCmluYyA6OiBJbnQgLT4gSW50CmluYyBuID0gbiArIDEKCmV2YWxXaXRoQ291bnQgOjogVGVybSAtPiAoSW50LCBJbnQpCmV2YWxXaXRoQ291bnQgdCA9IGV2YWwnICgwLCB0KQogIHdoZXJlCiAgICBldmFsJyA6OiAoSW50LCBUZXJtKSAtPiAoSW50LCBJbnQpCiAgICBldmFsJyA9IHVuZGVmaW5lZAogICAgLS0gVGhlIGV4ZXJjaXNlIHdvcmtzIGJlc3QgaWYgeW91IG9ubHkgdXNlICJpbmMiIHRvI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