Ternary logic: Difference between revisions

Content added Content deleted
(→‎{{header|Groovy}}: new solution)
(→‎{{header|OCaml}}: simplified function logic)
Line 1,574: Line 1,574:
| Maybe -> Maybe
| Maybe -> Maybe


let t_and a b =
let t_and a b = match (a,b) with
| (True,True) -> True
match a with
| True -> b
| (False,_) | (_,False) -> False
| False -> False
| _ -> Maybe
| Maybe ->
match b with
| False -> False
| _ -> Maybe


let t_or a b =
let t_or a b = t_not (t_and (t_not a) (t_not b))
match a with
| True -> True
| False -> b
| Maybe ->
match b with
| True -> True
| _ -> Maybe


let t_eq a b =
let t_eq a b = match (a,b) with
| (True,True) | (False,False) -> True
match a with
| True -> b
| (False,True) | (True,False) -> False
| Maybe -> Maybe
| _ -> Maybe
| False ->
match b with
| True -> False
| False -> True
| Maybe -> Maybe


let t_imply a b =
let t_imply a b = t_or (t_not a) b
match a, b with
| _, True -> True
| True, b -> b
| False, _ -> True
| Maybe, _ -> Maybe


let string_of_trit = function
let string_of_trit = function