aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/type/variance.lux
blob: b4fe87431ba609ab08774ed616b1e198c9e52686 (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
(.using
 [library
  [lux (.except)
   [meta
    ["[0]" symbol]]]])

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

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

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

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

(template [<name> <type>]
  [(template: .public (<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))

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

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