Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. module Main where
  2.  
  3. import Prelude
  4.  
  5. import Control.Monad.Eff.Console (log)
  6. import TryPureScript (render, withConsole)
  7.  
  8. {--
  9. - Problem (tribools): traditional boolean logic involves two values: true and
  10. - false. However, it is sometimes beneficial to consider logics that involve
  11. - three values, traditional labeled `true`, `false`, and `indeterminate`
  12. - For example, SQL handles comparisons between booleans with potential NULL
  13. - values as a logic with three values.
  14. -
  15. - First complete the definition of the tribool algebraic datatype below:
  16. -}
  17.  
  18. data Tribool =
  19. Placeholder -- TODO: delete this line and fill in the definition!
  20.  
  21. {--
  22. - Then complete the definitions of the standard logic operations for tribools
  23. - below. There are several interpretations of the operators of tri-value
  24. - logic; here we will use Kleene's interpretation:
  25. -
  26. - A not A
  27. - --------
  28. - T F
  29. - I I
  30. - F T
  31. -
  32. - A B A /\ B
  33. - ------------
  34. - T T T
  35. - T I I
  36. - T F F
  37. - I T I
  38. - I I I
  39. - I F F
  40. - F T F
  41. - F I F
  42. - F F F
  43. -
  44. - A B A \/ B
  45. - ------------
  46. - T T T
  47. - T I T
  48. - T F T
  49. - I T T
  50. - I I I
  51. - I F I
  52. - F T I
  53. - F I I
  54. - F F F
  55. -
  56. - As you fill in the definitions, write several relevant test
  57. - cases in the main function below demonstrating that your
  58. - functions work. Note that the `log` function takes a string
  59. - which you can produce using the `show` function provided that
  60. - you implement the `show` function below. Each function
  61. - should have at least 3 tests associated with it.
  62. -}
  63.  
  64. -- N.B., this instance declaration defines the `show` function
  65. -- for Tribools.
  66. instance showTribool :: Show Tribool where
  67. show :: Tribool -> String
  68. show _ = "Placeholder" -- TODO: delete and fill me in
  69.  
  70. -- Returns true if and only if the given tribool is true.
  71. triboolToBool :: Tribool -> Boolean
  72. triboolToBool t = false -- TODO: delete and fill me in!
  73.  
  74. -- Returns the negation of the given tribool.
  75. triboolNot :: Tribool -> Tribool
  76. triboolNot t = Placeholder -- TODO: delete and fill me in!
  77.  
  78. -- Returns the conjunction of the given tribools.
  79. triboolAnd :: Tribool -> Tribool -> Tribool
  80. triboolAnd t1 t2 = Placeholder -- TODO: delete and fill me in!
  81.  
  82. -- Returns the disjunction of the given tribools.
  83. triboolOr :: Tribool -> Tribool -> Tribool
  84. triboolOr t1 t2 = Placeholder -- TODO: delete and fill me in!
  85.  
  86. main = render =<< withConsole do
  87. log "===== triboolToBool ====="
  88. -- TODO: triboolToBool tests should go here
  89. log "===== triboolNot ====="
  90. -- TODO: triboolNot tests should go here
  91. log "===== triboolAnd ====="
  92. -- TODO: triboolAnd tests should go here
  93. log "===== triboolOr ====="
  94. -- TODO: triboolOr tests should go here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement