0 | module Data.Linear.Interface
2 | import Data.Linear.Notation
3 | import Data.Linear.Bifunctor
4 | import public Data.Linear.Copies
10 | interface Consumable a where
15 | Consumable Void where consume v impossible
18 | Consumable () where consume u = u
22 | Consumable Bool where
27 | Consumable (!* a) where
28 | consume (MkBang v) = ()
32 | Consumable Int where
33 | consume = believe_me (\ 0 i : Int => ())
37 | export infixr 5 `seq`
42 | seq : Consumable a => a -@ b -@ b
43 | a `seq` b = let 1 () = consume a in b
46 | interface Duplicable a where
47 | duplicate : (1 v : a) -> 2 `Copies` v
50 | Duplicable Void where
51 | duplicate v impossible
55 | duplicate () = [(), ()]
58 | Duplicable Bool where
59 | duplicate True = [True, True]
60 | duplicate False = [False, False]
63 | Duplicable (!* a) where
64 | duplicate (MkBang v) = [MkBang v, MkBang v]
74 | interface Comonoid a where
76 | comult : a -@ LPair a a
80 | [AutoComonoid] Consumable a => Duplicable a => Comonoid a where
82 | comult x = pair (duplicate x)
85 | Comonoid (!* a) where
86 | counit (MkBang _) = ()
87 | comult (MkBang v) = MkBang v # MkBang v