]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Has.hs
Sync with symantic.
[comptalang.git] / lib / Hcompta / Has.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE ConstraintKinds #-}
3 {-# LANGUAGE UndecidableInstances #-}
4 {-# LANGUAGE UndecidableSuperClasses #-}
5 module Hcompta.Has where
6
7 import Data.Proxy (Proxy(..))
8 import GHC.Exts (Constraint)
9
10 -- * Class 'Has'
11 type Has ty a = (Get ty a, Set ty a)
12
13 -- ** Class 'Get'
14 class Get ty a where
15 get :: a -> ty
16
17 -- ** Class 'Set'
18 class Set ty a where
19 set :: ty -> a -> a
20
21 -- * Class 'HasI'
22 type HasI cl a = (GetI cl a, SetI cl a)
23
24 -- ** Type family ':@'
25 -- | Return the type associated with @cl@ and @a@,
26 -- and which is an instance of @cl (cl :@ a)@.
27 type family (:@) (cl:: * -> Constraint) (a:: *) :: *
28 infixr 9 :@
29
30 -- ** Class 'GetI'
31 class cl (cl:@a) => GetI cl a where
32 getI_ :: Proxy cl -> a -> cl:@a
33
34 -- | Convenient helper to be used with 'TypeApplications'.
35 getI :: forall cl a. GetI cl a => a -> cl:@a
36 getI = getI_ (Proxy::Proxy cl)
37
38 -- ** Class 'SetI'
39 class cl (cl:@a) => SetI cl a where
40 setI_ :: Proxy cl -> cl:@a -> a -> a
41
42 -- | Convenient helper to be used with 'TypeApplications'.
43 setI :: forall cl a. SetI cl a => cl:@a -> a -> a
44 setI = setI_ (Proxy::Proxy cl)