Making a ternary logic table, and I would like to make my own function for an operator that I'll call <=>
.
So, for example, I want to do this, but that isn't right. what's the correct way to do this?
data Ternary = T | F | M
deriving (Eq, Show, Ord)
<=> :: Ternary -> Ternary -> Ternary
<=> T F = F
<=> T T = T
<=> T M = M
<=> F F = T
<=> F T = F
<=> F M = M
<=> M F = M
<=> M T = M
<=> M M = T
You can simplify (line-wise) the definition as follows:
Just add parentheses around your operator:
This turns it from infix form to prefix form. Alternatively, you can just use infix in the definition:
Since you have
Eq
andOrd
, you can do the following:If you do happen to change it so that
M <=> M == M
, then you can do the following:Function names with symbols have different syntax than those without:
I promise, though - Haskell is well worth learning the complex rules.