!'nػ      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~None,-.7=>?@AHUVX_k;generic-data-surgeryPEquate two generic representations, but ignoring constructor and field metadata.generic-data-surgerySThis is polymorphic to allow different ways of specifying the inserted constructor.If sym# (the kind of the constructor name c) is:-: treat it like a regular prefix constructor.+TODO Infix constructors and their fixities.t must be a single-constructor type, then we reuse its generic representation for the new constructor, only replacing its constructor name with c.generic-data-surgeryLike ,, but without the explicit constructor type.!generic-data-surgery%Number of constructors of a data type"generic-data-surgery(Number of fields of a single constructor#generic-data-surgeryPosition of a record field.generic-data-surgeryLike /% but without the explicit field type.5generic-data-surgery A constraint  Perform r s means that the surgery s/ can be applied to the generic representation r.7generic-data-surgeryUse this if a patient ever needs to go out and back into the operating room, when it's not just to undo the surgery up to that point.8generic-data-surgery*The identity surgery: doesn't do anything.9generic-data-surgery)Composition of surgeries (left-to-right).Note1Surgeries work on normalized representations, so =, which applies a surgery to a generic representation, inserts normalization steps before and after the surgery. This means that = r (s1 9 s2) is not quite the same as = (= r s1) s2(. Instead, the latter is equivalent to = r (s1 9 7 9 s2), where 70 inserts some intermediate normalization steps.:generic-data-surgeryApply a surgery s( to a linearized generic representation l.;generic-data-surgeryInternal definition of =.<generic-data-surgeryInternal definition of >.=generic-data-surgery Operate f s. Apply a surgery s to a generic representation f (e.g., f =  a for some  type a).The first argument is the generic representation; the second argument is the surgery, which typically has the more complex syntax, which is why this reverse application order was chosen.>generic-data-surgeryBKind of surgeries: operations on generic representations of types.GTreat this as an abstract kind (don't pay attention to its definition).Implementation details The name Surgery! got taken first by generic-data.k1 is the kind of the extra parameter reserved for Generic1, which we just don't use.Ygeneric-data-surgery A variant of Z allowing t and t' to be inferred.Zgeneric-data-surgery/This constraint means that the constructor row lc contains a constructor named c at position n of type isomorphic to t, and modifying it to t' yields row lc'.[generic-data-surgery A variant of \ allowing t to be inferred.\generic-data-surgery3This constraint means that inserting a constructor c at position n in the constructor row l yields row lc. Furthermore, constructor c contains a field row l_t! compatible with the tuple type t.]generic-data-surgery A variant of ^ allowing t to be inferred.^generic-data-surgery/This constraint means that the constructor row lc contains a constructor named c at position n, and removing it from lc yields row l. Furthermore, constructor c contains a field row l_t! compatible with the tuple type t._generic-data-surgery-This constraint means that modifying a field t named fd at position n to t' in the record field row lt yields row lt'. l is the row of fields common to lt and lt'.`generic-data-surgery-This constraint means that modifying a field t to t' at position n in the (unnamed) field row lt yields row lt'. l is the row of fields common to lt and lt'.ageneric-data-surgery-This constraint means that inserting a field t named fd at position n in the record field row l yields row lt.bgeneric-data-surgery-This constraint means that inserting a field t at position n in the (unnamed) field row l yields row lt.cgeneric-data-surgery0This constraint means that the record field row lt contains a field of type t named fd at position n, and removing it yields row l.dgeneric-data-surgery3This constraint means that the (unnamed) field row lt contains a field of type t at position n, and removing it yields row l.egeneric-data-surgery Similar to hA, but as a constraint on the standard generic representation of a directly, f ~  a.fgeneric-data-surgery Similar to  FromLazyORRepA, but as a constraint on the standard generic representation of a directly, f ~  a.ggeneric-data-surgeryThis constraint means that a is convertible from its simplified and normalized generic representation (i.e., with all its strictness annotations normalized to lazy defaults). Implies m a ~ o l ().hgeneric-data-surgeryThis constraint means that a is convertible to its simplified and normalized generic representation (i.e., with all its strictness annotations normalized to lazy defaults). Implies m a ~ o l ().igeneric-data-surgery Similar to kA, but as a constraint on the standard generic representation of a directly, f ~  a.jgeneric-data-surgery Similar to lA, but as a constraint on the standard generic representation of a directly, f ~  a.kgeneric-data-surgeryThis constraint means that a is convertible from1 its simplified generic representation. Implies n a ~ o l ().lgeneric-data-surgeryThis constraint means that a is convertible to1 its simplified generic representation. Implies n a ~ o l ().mgeneric-data-surgeryBThe simplified and normalized generic representation type of type a, that s and w convert to and from.ngeneric-data-surgery3The simplified generic representation type of type a, that r and v convert to and from.ogeneric-data-surgeryAA sterile Operating Room, where generic data comes to be altered.-Generic representation in a simplified shape l3 at the type level (reusing the constructors from  GHC.GenericsX for convenience). This representation makes it easy to modify fields and constructors.(We may also refer to the representation l as a "row" of constructors, if it represents a sum type, otherwise it is a "row" of unnamed fields or record fields for single-constructor types.x& corresponds to the last parameter of ;, and is currently ignored by this module (no support for ).General sketch A toOR surgeries fromOR' data MyType --------> OR (Rep MyType) ----------> OR alteredRep ---------> Data alteredRep | | myGenericFun :: Generic a => a -> a fromOR surgeries toOR' v data MyType <-------- OR (Rep MyType) <---------- OR alteredRep <--------- Data alteredRep  If instead  myGenericFun is only a consumer of aq (resp. producer), then you only need the top half of the diagram (resp. bottom half). For example, in aeson:  genericToJSON (consumer), genericParseJSON (producer).rgeneric-data-surgeryFMove fresh data to the Operating Room, where surgeries can be applied.3Convert a generic type to a generic representation.When inserting or removing fields, there may be a mismatch with strict/unpacked fields. To work around this, you can switch to sA, if your operations don't care about dealing with a normalized R (in which all the strictness annotations have been replaced with lazy defaults).DetailsType parameters a :: ! -- Generic type l :: k -> D -- Generic representation (simplified) x :: k -- Ignored Functional dependencies a -> l sgeneric-data-surgeryKMove normalized data to the Operating Room, where surgeries can be applied.Convert a generic type to a generic representation, in which all the strictness annotations have been normalized to lazy defaults.AThis variant is useful when one needs to operate on fields whose = has different strictness annotations than the ones used by ).DetailsType parameters a :: ! -- Generic type l :: k -> S -- Generic representation (simplified and normalized) x :: k -- Ignored Functional dependencies a -> l tgeneric-data-surgery>Move altered data out of the Operating Room, to be consumed by some generic function.YConvert a generic representation to a "synthetic" type that behaves like a generic type.DetailsType parameters  f :: k ->  -- # representation (proper) l :: k -> D -- Generic representation (simplified) x :: k -- Ignored Functional dependencies f -> l l -> f Implementation detailsThe synthesized representation is made of balanced binary trees, corresponding closely to what GHC would generate for an actual data type.@That structure assumed by at least one piece of code out there (aeson).ugeneric-data-surgeryFMove altered data, produced by some generic function, to the operating room.The inverse of t.DetailsType parameters  f :: k ->  -- # representation (proper) l :: k -> D -- Generic representation (simplified) x :: k -- Ignored Functional dependencies f -> l l -> f vgeneric-data-surgeryAMove restored data out of the Operating Room and back to the real world.The inverse of r.0It may be useful to annotate the output type of v, since the rest of the type depends on it and the only way to infer it otherwise is from the context. The following annotations are possible: v :: n a -> a v @a -- with TypeApplications When inserting or removing fields, there may be a mismatch with strict/unpacked fields. To work around this, you can switch to wA, if your operations don't care about dealing with a normalized R (in which all the strictness annotations have been replaced with lazy defaults).DetailsType parameters a :: ! -- Generic type l :: k -> D -- Generic representation (simplified) x :: k -- Ignored Functional dependencies a -> l wgeneric-data-surgeryCMove normalized data out of the Operating Room and back to the real world.The inverse of s.0It may be useful to annotate the output type of w, since the rest of the type depends on it and the only way to infer it otherwise is from the context. The following annotations are possible: w :: m a -> a w @a -- with TypeApplications DetailsType parameters a :: ! -- Generic type l :: k -> S -- Generic representation (simplified and normalized) x :: k -- Ignored Functional dependencies a -> l xgeneric-data-surgeryx @n @t : remove the n-th field, of type t+, in a non-record single-constructor type. Inverse of z.DetailsType parameters n ::  -- Field position t ::  -- Field type lt :: k -> " -- Row with field l :: k -> 3 -- Row without field x :: k -- Ignored  Signature o% lt x -- Data with field -> (t, o+ l x) -- Field value Data without field Functional dependencies n lt -> t l n t l -> lt ygeneric-data-surgeryy @"fdName" @n @t: remove the field fdName at position n of type t in a record type. Inverse of |.DetailsType parameters fd ::  -- Field name n ::  -- Field position t ::  -- Field type lt :: k -> " -- Row with field l :: k -> 3 -- Row without field x :: k -- Ignored  Signature o% lt x -- Data with field -> (t, o+ l x) -- Field value Data without field Functional dependencies 5fd lt -> n t l n lt -> fd t l fd n t l -> lt zgeneric-data-surgeryz @n @t: insert a field of type t at position n) in a non-record single-constructor type. Inverse of x.DetailsType parameters n ::  -- Field position t ::  -- Field type lt :: k -> " -- Row with field l :: k -> 3 -- Row without field x :: k -- Ignored  Signature (t, o. l x) -- Field value Data without field -> o lt x -- Data with field Functional dependencies n lt -> t l n t l -> lt {generic-data-surgeryCurried z.|generic-data-surgery| @"fdName" @n @t: insert a field named fdName of type t at position n in a record type. Inverse of y.DetailsType parameters fd ::  -- Field name n ::  -- Field position t ::  -- Field type lt :: k -> " -- Row with field l :: k -> 3 -- Row without field x :: k -- Ignored  Signature (t, o. l x) -- Field value Data without field -> o lt x -- Data with field Functional dependencies 5fd lt -> n t l n lt -> fd t l fd n t l -> lt }generic-data-surgeryCurried |.~generic-data-surgery~ @n @t @t': modify the field at position n! in a non-record via a function  f :: t -> t'" (changing the type of the field).DetailsType parameters n :: ! -- Field position t :: $ -- Initial field type t' :: ) -- Final field type lt :: k -> ( -- Row with initial field lt' :: k -> ( -- Row with final field l :: k -> 4 -- Row without field x :: k -- Ignored  Signature $(t -> t') -- Field modification -> o! lt x -- Data with field t -> o lt' x -- Data with field t' Functional dependencies 9n lt -> t l n lt' -> t' l n t l -> lt n t' l -> lt' generic-data-surgery @"fdName" @n @t @t': modify the field fdName at position n in a record via a function  f :: t -> t'# (changing the type of the field).DetailsType parameters fd ::  -- Field name n :: ! -- Field position t :: $ -- Initial field type t' :: ) -- Final field type lt :: k -> ( -- Row with initial field lt' :: k -> ( -- Row with final field l :: k -> 4 -- Row without field x :: k -- Ignored  Signature $(t -> t') -- Field modification -> o! lt x -- Data with field t -> o lt' x -- Data with field t' Functional dependencies ufd lt -> n t l fd lt' -> n t' l n lt -> fd t l n lt' -> fd t' l fd n t l -> lt fd n t' l -> lt' generic-data-surgery @"C" @n @t : remove the n-th constructor, named C), with contents isomorphic to the tuple t. Inverse of .DetailsType parameters c ::  -- Constructor name t :: 1 -- Tuple type to hold c's contents n :: , -- Constructor position lc :: k -> ) -- Row with constructor l :: k -> ) -- Row without constructor l_t :: k -> = -- Field row of constructor c x :: k -- Ignored  Signature o7 lc x -- Data with constructor -> Either t (o> l x) -- Constructor (as a tuple) | Data without constructor Functional dependencies :c lc -> n l l_t n lc -> c l l_t c n l l_t -> lc .Note that there is no dependency to determine t.generic-data-surgery A variant of  that can infer the tuple type t2 to hold the contents of the removed constructor.See .DetailsExtra functional dependency  l_t -> t generic-data-surgery @"C" @n @t: insert a constructor C at position n( with contents isomorphic to the tuple t. Inverse of .DetailsType parameters c ::  -- Constructor name t :: 1 -- Tuple type to hold c's contents n :: , -- Constructor position lc :: k -> ) -- Row with constructor l :: k -> ) -- Row without constructor l_t :: k -> = -- Field row of constructor c x :: k -- Ignored  Signature  Either t (oA l x) -- Constructor (as a tuple) | Data without constructor -> o* lc x -- Data with constructor Functional dependencies :c lc -> n l l_t n lc -> c l l_t c n l l_t -> lc .Note that there is no dependency to determine t.generic-data-surgery A variant of  that can infer the tuple type t3 to hold the contents of the inserted constructor.See .DetailsExtra functional dependency  l_t -> t generic-data-surgery @"C" @n @t @t' : modify the n-th constructor, named C(, with contents isomorphic to the tuple t, to another tuple t'.DetailsType parameters c :: ! -- Constructor name t :: : -- Tuple type to hold c's initial contents t' :: : -- Tuple type to hold c's final contents n :: - -- Constructor position lc :: k -> / -- Row with initial constructor lc' :: k -> / -- Row with final constructor l :: k -> * -- Row without constructor l_t :: k -> 5 -- Initial field row of constructor c l_t' :: k -> F -- Final field row of constructor c x :: k -- Ignored  Signature *(t -> t') -- Constructor modification -> o- lc x -- Data with initial constructor -> o* lc' x -- Data with final constructor Functional dependencies }c lc -> n l l_t c lc' -> n l l_t' n lc -> c l l_t n lc' -> c l l_t' c n l l_t -> lc c n l l_t' -> lc' .Note that there is no dependency to determine t and t'.generic-data-surgery A variant of  that can infer the tuple types t and t'3 to hold the contents of the inserted constructor.See .DetailsExtra functional dependencies l_t -> t l_t' -> t'   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~opqrstuvwnmlkjihgfexyz{|}~dcba`_^]\[ZYXWVUTSRPQNOLMJKHIFGEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!  91None 9(*/5789=>YZ[\]^_`abcdefghijklmnorstuvwxyz{|}~9ortuvnswmxz{~y|}>5=98(/*7ljhekigfdb`ca_^\Z][Y      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrsttuvwxyz{|}~3generic-data-surgery-0.3.0.0-JHJ0EGu5LdS33RyS1nhjeiGeneric.Data.SurgeryGeneric.Data.Surgery.Internal+generic-data-0.8.3.0-AXGhVzR9HES4kP36AAx5VUGeneric.Data.Internal.DatafromDatatoDataDataIsTuple MatchFieldsConstrLinearize GInsertConstr gInsertConstrConstrArborify GRemoveConstr gRemoveConstr ConstrIndexInsertUConstrAtLInsertUConstrAtPerformLInsertConstrAtPerformLInsertConstrAt_PerformLInsertConstrAt0 RenameMeta RenameConConGraftInsertConstrAtRemoveUConstrAt_RemoveUConstrAtRemoveConstrAtPerformLRemoveConstrAtPerformLRemoveConstrAt_PerformLRemoveConstr RemoveConstrConstrAt GInsertField gInsertField GRemoveField gRemoveFieldCoArityArity FieldIndexSucc CheckFieldPerformLInsertPerformLInsert_ InsertFieldDefaultMetaSel RemoveRFieldPerformLRemoveFieldAtPerformLRemoveFieldAt_ RemoveFieldAt RemoveField_ RemoveField FieldNameOf FieldNameAt FieldTypeOf FieldTypeAtPerform_PerformPerformLSuture IdSurgery:>>OperateLOperate_ MajorSurgery_Operate MajorSurgerySplitAt LazifyMetaLazify Arborify'ArborifyProduct ArborifySumArborifyGArborifyProductgArborifyProduct GArborifySum gArborifySum GArborify gArborifyGLinearizeProductgLinearizeProduct GLinearizeSum gLinearizeSum GLinearize gLinearizeLinearizeProduct LinearizeSum Linearize ConstrSurgery RFieldSurgery CFieldSurgery FieldSurgery ModConstrT ModConstr InsConstrT InsConstr RmvConstrT RmvConstr ModRField ModCField InsRField InsCField RmvRField RmvCFieldToORLazy FromORLazy FromORRepLazy ToORRepLazyFromORToOR FromORRepToORRepOROfLazyOROfORunORtoORtoORLazyfromOR'toOR'fromOR fromORLazy removeCField removeRField insertCField insertCField' insertRField insertRField' modifyCField modifyRField removeConstr removeConstrT insertConstr insertConstrT modifyConstr modifyConstrTconstrArborify'constrLinearize'$fGLinearizeSumk:+:tl$fGLinearizeSumkV1tl$fGLinearizekM1$fGLinearizeProductkM1tl$fGLinearizeProductk:*:tl$fGLinearizeProductkU1tl$fGLinearizeSumkM1tl$fGLinearizekM10$fGArborifySumk:+:tl$fGArborifySumkV1tl$fGArborifykM1$fGArborifyProductkM1tl$fGArborifyProductk:*:tl$fGArborifyProductkU1tl$fGArborifySumkM1tl$fGArborifykM10 $fPerformkrs$fGRemoveFieldkna:*:f0g$fGRemoveFieldk0a:*:f$fGRemoveFieldkna:+::+:$fGRemoveFieldknaM1M1$fPerformLRemoveFieldAtknfdtltl$fGInsertFieldknaf0f:*:$fGInsertFieldk0af:*:$fGInsertFieldkna:+::+:$fGInsertFieldknaM1M1$fPerformLInsertknfdtltl$fGRemoveConstrknt:+:f0g$fGRemoveConstrkntM1M1$fGRemoveConstrTYPE0t:+:f$fGInsertConstrkntf0f:+:$fGInsertConstrkntM1M1$fGInsertConstrTYPE0tf:+:$fMatchFieldskV1g$fMatchFieldskU1g$fMatchFieldskK1g$fMatchFieldsk:*:g$fMatchFieldsk:+:g$fMatchFieldskM1g$fMatchFieldskM1g0$fMatchFieldskM1g1!$fPerformLInsertConstrAtcntl_tllc!$fPerformLRemoveConstrAtcntl_tlcl$fIsTupleTYPE7t$fIsTupleTYPE6t$fIsTupleTYPE5t$fIsTupleTYPE4t$fIsTupleTYPE3t$fIsTupleTYPE2t$fIsTupleTYPE1t$fIsTupleTYPE0tghc-prim GHC.TypesSymbolbase GHC.GenericsRepGenericGeneric1TypeNat