-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Supercharged anonymous records -- -- Anonymous records with various useful utilities @package superrecord @version 0.2.0.0 module SuperRecord -- | Field named l labels value of type t adapted from -- the awesome labels package. Example: (#name := "Chris") :: -- ("name" := String) data (:=) label value (:=) :: FldProxy label -> !value -> (:=) label value -- | The core record type. data Rec (lts :: [*]) -- | An empty record rnil :: Rec '[] -- | Prepend a record entry to a record Rec rcons :: forall l t lts s. (RecSize lts ~ s, KnownNat s, KeyDoesNotExist l lts) => l := t -> Rec lts -> Rec ((l := t) : lts) -- | Alias for rcons (&) :: forall l t lts s. (RecSize lts ~ s, KnownNat s, KeyDoesNotExist l lts) => l := t -> Rec lts -> Rec ((l := t) : lts) infixr 5 & -- | Helper function to allow to clearing specify unknown IsLabel -- cases fld :: FldProxy l -> FldProxy l -- | Require a record to contain a label type Has l lts v = (RecTy l lts ~ v, KnownNat (RecSize lts), KnownNat (RecVecIdxPos l lts)) -- | Require a record to contain at least the listed labels -- | Get an existing record field get :: forall l v lts. (Has l lts v) => FldProxy l -> Rec lts -> v -- | Alias for get (&.) :: forall l v lts. (Has l lts v) => Rec lts -> FldProxy l -> v infixl 3 &. -- | Update an existing record field set :: forall l v lts. (Has l lts v) => FldProxy l -> v -> Rec lts -> Rec lts -- | Update an existing record field modify :: forall l v lts. (Has l lts v) => FldProxy l -> (v -> v) -> Rec lts -> Rec lts -- | Perform a deep read. This is somewhat similar to using (&.), but -- is useful when you want to share a RecPath between -- getPath, modifyPath and/or setPath getPath :: RecApplyPath k x => k -> Rec x -> RecDeepTy k x -- | Perform a deep update, setting the key along the path to the desired -- value setPath :: RecApplyPath k x => k -> RecDeepTy k x -> Rec x -> Rec x -- | Perform a deep update, transforming the value at the final key modifyPath :: RecApplyPath k x => k -> (RecDeepTy k x -> RecDeepTy k x) -> Rec x -> Rec x class RecApplyPath p x -- | Constructor for field accessor paths data (:&) lbl more -- | Constructor for field accessor paths (&:) :: FldProxy q -> more -> q :& more infixr 8 &: -- | Specialized version of (&:) to help writing the last piece of the -- path w/o confusing the type checker (&:-) :: FldProxy q -> FldProxy r -> q :& FldProxy r infixr 8 &:- -- | Combine two records combine :: forall lhs rhs. (KnownNat (RecSize lhs), KnownNat (RecSize rhs), KnownNat (RecSize lhs + RecSize rhs)) => Rec lhs -> Rec rhs -> Rec (RecAppend lhs rhs) -- | Alias for combine (++:) :: forall lhs rhs. (KnownNat (RecSize lhs), KnownNat (RecSize rhs), KnownNat (RecSize lhs + RecSize rhs)) => Rec lhs -> Rec rhs -> Rec (RecAppend lhs rhs) type RecAppend lhs rhs = RecAppendH lhs rhs rhs '[] -- | Apply a function to each key element pair for a record reflectRec :: forall c r lts. (RecApply lts lts c) => Proxy c -> (forall a. c a => String -> a -> r) -> Rec lts -> [r] -- | Machinery needed to implement reflectRec class RecApply (rts :: [*]) (lts :: [*]) c recApply :: RecApply rts lts c => (forall a. Dict (c a) -> String -> a -> r) -> Rec rts -> Proxy lts -> [r] -- | Conversion helper to bring a Haskell type to a record. Note that the -- native Haskell type must be an instance of Generic class FromNative a lts | a -> lts -- | Convert a native Haskell type to a record fromNative :: (Generic a, FromNative (Rep a) lts) => a -> Rec lts -- | Conversion helper to bring a record back into a Haskell type. Note -- that the native Haskell type must be an instance of Generic class ToNative a lts | a -> lts -- | Convert a record to a native Haskell type toNative :: (Generic a, ToNative (Rep a) lts) => Rec lts -> a -- | Like asks for MonadReader, but you provide a record -- field you would like to read from your environment asksR :: (Has lbl lts v, MonadReader (Rec lts) m) => FldProxy lbl -> m v -- | Like asks for MonadReader, but you provide a record -- field you would like to read from your environment asksRP :: (RecApplyPath k x, MonadReader (Rec x) m) => k -> m (RecDeepTy k x) -- | Like gets for MonadState, but you provide a record -- field you would like to read from your environment getsR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> m v -- | Similar to put for MonadState, but you only set a -- single record field setsR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> v -> m () -- | Similar to modify for MonadState, but you update a -- single record field modifiesR :: (Has lbl lts v, MonadState (Rec lts) m) => FldProxy lbl -> (v -> v) -> m () -- | Similar to gets for MonadState, but allows getting a -- value along a RecPath getsRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> m (RecDeepTy k x) -- | Similar to put for MonadState, but you only set a -- single record field setsRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> RecDeepTy k x -> m () -- | Similar to modify for MonadState, but you update a -- single record field modifiesRP :: (RecApplyPath k x, MonadState (Rec x) m) => k -> (RecDeepTy k x -> RecDeepTy k x) -> m () -- | Convert a field label to a lens lens :: Has l lts v => FldProxy l -> Lens (Rec lts) (Rec lts) v v -- | Convert all elements of a record to a String showRec :: forall lts. (RecApply lts lts Show) => Rec lts -> [(String, String)] -- | Get keys of a record on value and type level class RecKeys (lts :: [*]) where type RecKeysT lts :: [Symbol] where { type family RecKeysT lts :: [Symbol]; } recKeys :: RecKeys lts => t lts -> [String] -- | Machinery to implement equality class RecEq (rts :: [*]) (lts :: [*]) recEq :: RecEq rts lts => Rec rts -> Rec rts -> Proxy lts -> Bool recToValue :: forall lts. (RecApply lts lts ToJSON) => Rec lts -> Value recToEncoding :: forall lts. (RecApply lts lts ToJSON) => Rec lts -> Encoding recJsonParser :: forall lts s. (RecSize lts ~ s, KnownNat s, RecJsonParse lts) => Value -> Parser (Rec lts) -- | Machinery to implement parseJSON class RecJsonParse (lts :: [*]) recJsonParse :: RecJsonParse lts => Int -> Object -> Parser (Rec lts) -- | Machinery for NFData class RecNfData (lts :: [*]) (rts :: [*]) recNfData :: RecNfData lts rts => Proxy lts -> Rec rts -> () -- | A proxy witness for a label. Very similar to Proxy, but needed -- to implement a non-orphan IsLabel instance data FldProxy (t :: Symbol) FldProxy :: FldProxy instance GHC.Classes.Ord (SuperRecord.FldProxy t) instance GHC.Classes.Eq (SuperRecord.FldProxy t) instance GHC.Read.Read (SuperRecord.FldProxy t) instance GHC.Show.Show (SuperRecord.FldProxy t) instance GHC.Classes.Eq value => GHC.Classes.Eq (label SuperRecord.:= value) instance GHC.Classes.Ord value => GHC.Classes.Ord (label SuperRecord.:= value) instance GHC.Show.Show t => GHC.Show.Show (l SuperRecord.:= t) instance l ~ l' => GHC.OverloadedLabels.IsLabel l (SuperRecord.FldProxy l') instance SuperRecord.RecApply lts lts GHC.Show.Show => GHC.Show.Show (SuperRecord.Rec lts) instance SuperRecord.RecEq lts lts => GHC.Classes.Eq (SuperRecord.Rec lts) instance SuperRecord.RecApply lts lts Data.Aeson.Types.ToJSON.ToJSON => Data.Aeson.Types.ToJSON.ToJSON (SuperRecord.Rec lts) instance (SuperRecord.RecSize lts ~ s, GHC.TypeLits.KnownNat s, SuperRecord.RecJsonParse lts) => Data.Aeson.Types.FromJSON.FromJSON (SuperRecord.Rec lts) instance SuperRecord.RecNfData lts lts => Control.DeepSeq.NFData (SuperRecord.Rec lts) instance (SuperRecord.Has l lts t, t ~ SuperRecord.RecDeepTy (SuperRecord.FldProxy l) lts) => SuperRecord.RecApplyPath (SuperRecord.FldProxy l) lts instance (SuperRecord.RecDeepTy (l SuperRecord.:& more) lts ~ SuperRecord.RecDeepTy more rts, SuperRecord.RecTy l lts ~ SuperRecord.Rec rts, SuperRecord.Has l lts v, v ~ SuperRecord.Rec rts, SuperRecord.RecApplyPath more rts) => SuperRecord.RecApplyPath (l SuperRecord.:& more) lts instance SuperRecord.RecKeys '[] instance (GHC.TypeLits.KnownSymbol l, SuperRecord.RecKeys lts) => SuperRecord.RecKeys (l SuperRecord.:= t : lts) instance SuperRecord.RecApply rts '[] c instance (GHC.TypeLits.KnownSymbol l, SuperRecord.RecApply rts (SuperRecord.RemoveAccessTo l lts) c, SuperRecord.Has l rts v, c v) => SuperRecord.RecApply rts (l SuperRecord.:= t : lts) c instance SuperRecord.RecEq rts '[] instance (SuperRecord.RecEq rts (SuperRecord.RemoveAccessTo l lts), SuperRecord.Has l rts v, GHC.Classes.Eq v) => SuperRecord.RecEq rts (l SuperRecord.:= t : lts) instance SuperRecord.RecJsonParse '[] instance (GHC.TypeLits.KnownSymbol l, Data.Aeson.Types.FromJSON.FromJSON t, SuperRecord.RecJsonParse lts, SuperRecord.RecSize lts ~ s, GHC.TypeLits.KnownNat s, SuperRecord.KeyDoesNotExist l lts) => SuperRecord.RecJsonParse (l SuperRecord.:= t : lts) instance SuperRecord.RecNfData '[] rts instance (SuperRecord.Has l rts v, Control.DeepSeq.NFData v, SuperRecord.RecNfData (SuperRecord.RemoveAccessTo l lts) rts) => SuperRecord.RecNfData (l SuperRecord.:= t : lts) rts instance SuperRecord.FromNative cs lts => SuperRecord.FromNative (GHC.Generics.D1 m cs) lts instance SuperRecord.FromNative cs lts => SuperRecord.FromNative (GHC.Generics.C1 m cs) lts instance GHC.TypeLits.KnownSymbol name => SuperRecord.FromNative (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Base.Just name) p s l) (GHC.Generics.Rec0 t)) '[name SuperRecord.:= t] instance (SuperRecord.FromNative l lhs, SuperRecord.FromNative r rhs, lts ~ SuperRecord.RecAppend lhs rhs, GHC.TypeLits.KnownNat (SuperRecord.RecSize lhs), GHC.TypeLits.KnownNat (SuperRecord.RecSize rhs), GHC.TypeLits.KnownNat (SuperRecord.RecSize lhs GHC.TypeLits.+ SuperRecord.RecSize rhs)) => SuperRecord.FromNative (l GHC.Generics.:*: r) lts instance SuperRecord.ToNative cs lts => SuperRecord.ToNative (GHC.Generics.D1 m cs) lts instance SuperRecord.ToNative cs lts => SuperRecord.ToNative (GHC.Generics.C1 m cs) lts instance SuperRecord.Has name lts t => SuperRecord.ToNative (GHC.Generics.S1 ('GHC.Generics.MetaSel ('GHC.Base.Just name) p s l) (GHC.Generics.Rec0 t)) lts instance (SuperRecord.ToNative l lts, SuperRecord.ToNative r lts) => SuperRecord.ToNative (l GHC.Generics.:*: r) lts