Skip to content

Instantly share code, notes, and snippets.

@psosera
Created September 26, 2019 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psosera/18555ffd374a46a5377fac777af51cf8 to your computer and use it in GitHub Desktop.
Save psosera/18555ffd374a46a5377fac777af51cf8 to your computer and use it in GitHub Desktop.
CSC 208: Tribools Homework Problem
module Main where
import Prelude
import Control.Monad.Eff.Console (log)
import TryPureScript (render, withConsole)
{--
- Problem (tribools): traditional boolean logic involves two values: true and
- false. However, it is sometimes beneficial to consider logics that involve
- three values, traditional labeled `true`, `false`, and `indeterminate`
- For example, SQL handles comparisons between booleans with potential NULL
- values as a logic with three values.
-
- First complete the definition of the tribool algebraic datatype below:
-}
data Tribool =
Placeholder -- TODO: delete this line and fill in the definition!
{--
- Then complete the definitions of the standard logic operations for tribools
- below. There are several interpretations of the operators of tri-value
- logic; here we will use Kleene's interpretation:
-
- A not A
- --------
- T F
- I I
- F T
-
- A B A /\ B
- ------------
- T T T
- T I I
- T F F
- I T I
- I I I
- I F F
- F T F
- F I F
- F F F
-
- A B A \/ B
- ------------
- T T T
- T I T
- T F T
- I T T
- I I I
- I F I
- F T I
- F I I
- F F F
-
- As you fill in the definitions, write several relevant test
- cases in the main function below demonstrating that your
- functions work. Note that the `log` function takes a string
- which you can produce using the `show` function provided that
- you implement the `show` function below. Each function
- should have at least 3 tests associated with it.
-}
-- N.B., this instance declaration defines the `show` function
-- for Tribools.
instance showTribool :: Show Tribool where
show :: Tribool -> String
show _ = "Placeholder" -- TODO: delete and fill me in
-- Returns true if and only if the given tribool is true.
triboolToBool :: Tribool -> Boolean
triboolToBool t = false -- TODO: delete and fill me in!
-- Returns the negation of the given tribool.
triboolNot :: Tribool -> Tribool
triboolNot t = Placeholder -- TODO: delete and fill me in!
-- Returns the conjunction of the given tribools.
triboolAnd :: Tribool -> Tribool -> Tribool
triboolAnd t1 t2 = Placeholder -- TODO: delete and fill me in!
-- Returns the disjunction of the given tribools.
triboolOr :: Tribool -> Tribool -> Tribool
triboolOr t1 t2 = Placeholder -- TODO: delete and fill me in!
main = render =<< withConsole do
log "===== triboolToBool ====="
-- TODO: triboolToBool tests should go here
log "===== triboolNot ====="
-- TODO: triboolNot tests should go here
log "===== triboolAnd ====="
-- TODO: triboolAnd tests should go here
log "===== triboolOr ====="
-- TODO: triboolOr tests should go here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment