aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/type/variance.lux
blob: f7828e49a3bf1f572e8208dc031a43b221bf1117 (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
(.require
 [library
  [lux (.except)]])

(type .public (Co it)
  (-> Any it))

(type .public (Contra it)
  (-> it Any))

(type .public (In it)
  (-> it it))

(type .public (Mutable r w)
  (Nominal "#Mutable" [(-> w r)]))

(with_template [<name> <type>]
  [(def .public <name>
     (template (<name> it)
       [((.is (.All (_ r w) <type>)
              (.|>> .as_expected))
         it)]))]

  [read (.-> (..Mutable r w) r)]
  [write (.-> w (..Mutable r w))]
  )

(type .public (Read_Only a)
  (Mutable a Nothing))

(type .public (Write_Only a)
  (Mutable Any a))

(with_template [<name> <type>]
  [(def .public <name>
     (template (<name> it)
       [((.is (.All (_ r w) <type>)
              (.|>>))
         it)]))]

  [read_only (.-> (..Mutable r w) (..Read_Only r))]
  [write_only (.-> (..Mutable r w) (..Write_Only w))]
  )