Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exception NotEnaughOp of code;;
- raise (NotEnaughOp s)
- type code = Elem of bool | Not | And | Or | Xor;;
- let eval listOfOper =
- let getVal l x =
- if x = Not then not (List.hd l)
- else if (List.tl l = []) then raise (NotEnaughOp x)
- else (
- match x with
- | And -> (List.hd l) && (List.hd (List.tl l))
- | Or -> (List.hd l) || (List.hd (List.tl l))
- | Xor -> ((List.hd l) && not (List.hd (List.tl l))) || (not (List.hd l) && (List.hd (List.tl l)))
- )
- in
- let rec evalH (listOfOper, acc, currVal) =
- match listOfOper with
- [] -> List.hd acc
- | (x :: xs) -> if x = Elem true then evalH(xs, true :: acc, true)
- else if x = Elem false then evalH(xs, false :: acc, false)
- else evalH(xs, [(getVal acc x)], (getVal acc x))
- in
- evalH (listOfOper, [], false) ;;
Add Comment
Please, Sign In to add comment