How do I create an operator in Haskell?

前端 未结 4 1536
栀梦
栀梦 2021-02-03 22:24

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

4条回答
  •  时光说笑
    2021-02-03 22:42

    Just add parentheses around your operator:

    (<=>) :: 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
    

    This turns it from infix form to prefix form. Alternatively, you can just use infix in the definition:

    (<=>) :: 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
    

提交回复
热议问题