aboutsummaryrefslogtreecommitdiff
path: root/source/lux/data/bool.lux
blob: defaee22e2b8617e323a245594230829ca4af7ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
##  Copyright (c) Eduardo Julian. All rights reserved.
##  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
##  If a copy of the MPL was not distributed with this file,
##  You can obtain one at http://mozilla.org/MPL/2.0/.

(;import lux
         (lux (control (monoid #as m)
                       (eq #as E)
                       (show #as S))
              (codata function)))

## [Structures]
(defstruct #export Bool/Eq (E;Eq Bool)
  (def (= x y)
    (if x
      y
      (not y))))

(defstruct #export Bool/Show (S;Show Bool)
  (def (show x)
    (if x "true" "false")))

(do-template [<name> <unit> <op>]
  [(defstruct #export <name> (m;Monoid Bool)
     (def unit <unit>)
     (def (++ x y)
       (<op> x y)))]

  [ Or/Monoid false or]
  [And/Monoid true and]
  )

## [Functions]
(def #export complement
  (All [a] (-> (-> a Bool) (-> a Bool)))
  (. not))