[Haskell-cafe] How to express a logic matrix clearly?

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Fri May 17 09:37:20 UTC 2019


On Thu, May 16, 2019 at 10:21:14PM -0500, Nathan Bloomfield wrote:
> This is a good opportunity to use case syntax. You can also case on tuples,
> like this:
> 
> ```
> foo a b = case (a,b) of
>   (A1,B1) -> fun1
>   (A1,B2) -> fun2
>   (A1,B3) -> fun3
>   (A1,_)  -> fun4   <- this is probably not necessary anymore, unless you
> expect Rule2 to get more constructors.
>   (A2,B1) -> fun5
>   ...
> ```

In fact, and this is veering somewhat off-topic, but I would strongly
recommend *not* making a default match `(A1,_)` because then you will get an
explicit warning if indeed `Rule2` gets more constructors.


More information about the Haskell-Cafe mailing list