Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

implement ternary logic in Haskell import Data List This hw is to implement oper

ID: 3844282 • Letter: I

Question

implement ternary logic in Haskell

import Data List This hw is to implement operators and expression trees in ternary logic in Haskell add code in all the places marked TODO You can add helper functions if you need to But DO NOT make any change the code of the test functions. Ternary logic: use the constructors T, Fand Mfor True, False and Maybe The basic operation of ternary logic are not, and, or, equivalence and implication with the truth table below. To avoid conflict with the haskell's Bool implementation we'll use the following names: n't for not &&& for and III to or for equivalence for implication Truth Table N't x M

Explanation / Answer

The ternary method in Haskell language is as follows:

Ternary.hs

import Prelude hiding (Bool(..), not, (&&), (||), (==))

main = mapM_ (putStrLn . unlines . map unwords)
[ table "not" $ unary not
, table "and" $ binary (&&)
, table "or" $ binary (||)
, table "implies" $ binary (==>)
, table "equals" $ binary (==)
]

data Trit = False | Maybe | True

False `nand` _ = True
_ `nand` False = True
True `nand` True = False
_ `nand` _ = Maybe

not op = nand op op

op && ui = not $ op `nand` ui

op || ui = not op `nand` not ui

op =-> ui = op `nand` not ui

op == ui = (op && ui) || (not op && not ui)

ip1 = [True, Maybe, False]
ip2 = [(op,ui) | op <- ip1, ui <- ip1]

unary po = map (op -> [op, po op]) ip1
binary po = map ((op,ui) -> [op, ui, po op ui]) ip2

table name gf = map (map pad) . (header :) $ map (map show) gf
where header = map (:[]) (take ((length $ head gf) - 1) ['op'..]) ++ [name]

pad qe = qe ++ replicate (5 - length qe) ' '

Please rate the answer if it healped.. Thankyou

Hope it helped..