1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE ConstraintKinds #-}
3 {-# LANGUAGE UndecidableInstances #-}
4 {-# LANGUAGE UndecidableSuperClasses #-}
5 module Hcompta.Has where
7 import Data.Proxy (Proxy(..))
8 import GHC.Exts (Constraint)
11 type Has ty a = (Get ty a, Set ty a)
22 type HasI cl a = (GetI cl a, SetI cl a)
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:: *) :: *
31 class cl (cl:@a) => GetI cl a where
32 getI_ :: Proxy cl -> a -> cl:@a
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)
39 class cl (cl:@a) => SetI cl a where
40 setI_ :: Proxy cl -> cl:@a -> a -> a
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)