blob: b78351b38924c31a76f122913ab5da0bb3acdd57 (
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
46
47
48
49
50
51
|
(.module:
[lux #*
[control
[functor (#+ Functor)]
[apply (#+ Apply)]
[monad (#+ Monad)]]
[data
[error (#+ Error)]]
[type
abstract]])
(abstract: #export (Dirty a)
{#.doc (doc "A value which is considered untrustworthy due to its origin.")}
a
(def: #export taint
{#.doc (doc "Mark a value as dirty/untrustworthy.")}
(All [a] (-> a (Dirty a)))
(|>> :abstraction))
(def: #export (validate validator dirty)
{#.doc (doc "Test a dirty/untrustworthy value."
"Potentially produces a 'clean' value.")}
(All [a b] (-> (-> a (Error b)) (Dirty a) (Error b)))
(validator (:representation dirty)))
(def: #export trust
{#.doc (doc "Trusts a (previously thought as) dirty/untrustworthy value."
"Only use this function if you know what you are doing."
"Trusting a value that hasn't been validated opens a security vulnerability.")}
(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)))
)
|