Ternary logic implementation in Haskell import Data List This hw is to implement
ID: 3844245 • Letter: T
Question
Ternary logic implementation 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 MExplanation / Answer
ifs in Haskell aren't terribly pretty, but that's not really the reason they're used so seldom. It's more because there's usually a more elegant syntactic alternative! In your example, I would consider
Alternatively, you might define an already partially evaluated operator locally:
You definitely do not want to do the check on isAtBottom multiple times, redundant code is always bad, regardless of which syntax you use. But when you do just need a single decision based on a simple boolean value, I would stick to the standard if rather than defining custom operators.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.