99 questions/Solutions/47

From HaskellWiki
< 99 questions‎ | Solutions
Revision as of 19:50, 18 January 2014 by Henk-Jan van Tuyl (talk | contribs) (Added Category:Programming exercise spoilers)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

(*) Truth tables for logical expressions (2).

Continue problem P46 by defining and/2, or/2, etc as being operators. This allows to write the logical expression in the more natural way, as in the example: A and (A or not B). Define operator precedence as usual; i.e. as in Java.

-- functions as in solution 46
infixl 4 `or'`
infixl 6 `and'`
-- "not" has fixity 9 by default

Java operator precedence (descending) as far as I could fathom it:

logical not

Using "not" as a non-operator is a little evil, but then again these problems were designed for languages other than haskell :)