Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* 10th function *)
- fun traverse f_c f_v f_acc acc exp =
- case exp of
- Constant(x) => f_acc (f_c x, acc)
- | Variable(x) => f_acc (f_v x, acc)
- | Pair([x1,x2]) => f_acc (traverse f_c f_v f_acc acc x1, traverse f_c f_v f_acc acc x2)
- | Operator(_,exp1) => traverse f_c f_v f_acc acc exp1
- | List(head::tail) => f_acc (traverse f_c f_v f_acc acc head, traverse f_c f_v f_acc acc (List(tail)))
- | _ => acc
- (* 7th function *)
- fun count_constants exp = traverse (fn x=>1) (fn x=>0) op+ 0 exp
- (* 8th function *)
- fun sum_constants exp = traverse (fn x=>x) (fn x=>0) op+ 0 exp
- (* 9th function *)
- fun all_variables exp = traverse (fn x=>[]) (fn x=>[x]) (fn (x,acc) => (List.filter (fn y=>null x orelse y<>hd x) acc) @ x) [] exp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement