aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/security/taint.lux
blob: 745baa95f84cd1eac6aa656428d27b18f4157902 (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
37
38
39
40
41
42
43
44
45
(.module:
  [lux #*
   [control
    [predicate (#+ Predicate)]
    [functor (#+ Functor)]
    [apply (#+ Apply)]
    [monad (#+ Monad)]]
   [type
    abstract]])

(abstract: #export (Dirty a)
  a

  (def: #export taint
    (All [a] (-> a (Dirty a)))
    (|>> :abstraction))

  (def: #export (validate valid? dirty)
    (All [a] (-> (Predicate a) (Dirty a) (Maybe a)))
    (let [value (:representation dirty)]
      (if (valid? value)
        (#.Some value)
        #.None)))

  (def: #export trust
    (All [a] (-> (Dirty a) a))
    (|>> :representation))

  (structure: #export _ (Functor Dirty)
    (def: (map f fa)
      (|> fa :representation f :abstraction)))

  (structure: #export _ (Apply Dirty)
    (def: functor Functor<Dirty>)

    (def: (apply ff fa)
      (:abstraction ((:representation ff) (:representation fa)))))

  (structure: #export _ (Monad Dirty)
    (def: functor Functor<Dirty>)

    (def: wrap (|>> :abstraction))

    (def: join (|>> :representation)))
  )