How do I create an operator in Haskell?

前端 未结 4 1574
栀梦
栀梦 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:39

    Function names with symbols have different syntax than those without:

    -- Works:
    (<^>) :: Int -> Int -> Int
    a <^> b = a + b
    
    -- Doesn't work:
    {-
    <^> :: Int -> Int -> Int
    <^> a b = a + b
    -}
    
    -- Works:
    letters :: Int -> Int -> Int
    letters a b = a + b
    
    -- Doesn't work:
    {-
    (letters) :: Int -> Int -> Int
    a letters b = a + b
    -}
    

    I promise, though - Haskell is well worth learning the complex rules.

提交回复
热议问题