3{-# LANGUAGE PatternSynonyms #-}
4{-# LANGUAGE TypeApplications #-}
32import GHC.OverloadedLabels
35import JRec.Internal (FldProxy (..), Tup, (:=) (..))
36import JRec.Internal qualified as R
40----------------------------------------------------------------------------
42----------------------------------------------------------------------------
44unField :: (field ~ field') => R.FldProxy field -> (field' R.:= value) -> value
45unField _ (_ R.:= value) = value
47----------------------------------------------------------------------------
49----------------------------------------------------------------------------
51-- Appends records, without removing duplicates.
53-- O(n + m) type check complexity.
55-- FIXME: See spec for a bug when there are duplicates.
58 (res ~ R.RecAppend lhs rhs) =>
64-- Merges records, removing duplicates
66-- Left-biased. Does not sort.
68-- O(n * m) type check complexity.
71 ( KnownNat (R.RecSize lhs),
72 KnownNat (R.RecSize rhs),
73 KnownNat (R.RecSize res),
74 res ~ R.Union lhs rhs,
75 R.RecCopy lhs lhs res,
83-- | Insert a field into a record that does not already contain it
85-- O(n) type check complexity.
87 forall label value lts res.
88 ( KnownNat (1 + R.RecSize lts),
89 KnownNat (R.RecSize lts),
91 R.RecCopy lts lts res,
92 res ~ ((label := value) : lts),
93 R.RemoveAccessTo label lts ~ lts
98insert = R.combine . Tup
100-- | Insert a field into a record. Set it if it already exists
102-- O(n) type check complexity.
104 forall label value rhs res.
105 ( KnownNat (R.RecSize rhs),
106 KnownNat (R.RecSize res),
107 KnownNat (R.RecTyIdxH 0 label res),
109 value ~ R.RecTy label res,
110 R.Reverse (R.Insert (label := value) (R.Reverse rhs)) ~ res,
111 R.RecCopy rhs rhs res
116insertOrSet = R.insert
118----------------------------------------------------------------------------
120----------------------------------------------------------------------------
122type Sel name value = S1 ('MetaSel ('Just name) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 value)
124type family Sels fields where
126 Sels '[name R.:= value] = Sel name value
127 Sels ((name R.:= value) ': xs) = Sel name value :*: Sels xs
129type RecordRep fields =
131 ('MetaData "Record" "Rec" "" 'False)
133 ('MetaCons "Record" 'PrefixI 'True)
137-- instance (R.FromNative (RecordRep fields) fields, R.ToNative (RecordRep fields) fields) => Generic (Tup fields) where
138-- type Rep (Tup fields) = RecordRep fields
143 ( RecTuple tuple fields
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list