!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ (C) 2013 Hugo PachecoBSD-style (see below)!Hugo Pacheco <hpacheco@nii.ac.jp> provisionalNone$%&09:;ADLQRTa None$%&09:;ADLQRTa"Expressions are patterns whose variable positions contain directions pointing into some environment. Their type is indexed by the environment type and the type of the expressed value.>Direction expression, referring to a value in the environment.Constant expression.Product expression.Left expression (producing an -value).Right expression (producing an -value).XConstructor expression, wrapping a sum-of-products representation into data. (Invoke  ! on the datatype involved first.)3Directions point to a variable position (marked by  }) in an environment. Their type is indexed by the environment type and the type of the variable position being pointed to.'Point to the current variable position. *Point to the left part of the environment. +Point to the right part of the environment. 5A marker for variable positions in environment types. The datatype of patterns is indexed by three types: the type of values to which a pattern is applicable, the type of environments resulting from pattern matching, and the type of containers used during inverse evaluation of expressions.CVariable pattern, the value extracted from which can be duplicated.FVariable pattern, the value extracted from which cannot be duplicated.Constant pattern.Product pattern.PLeft pattern, matching values of shape `Left x :: Either a b` for some `x :: a`.RRight pattern, matching values of shape `Right y :: Either a b` for some `y :: b`.ZConstructor pattern, unwrapping a value to its sum-of-products representation. (Invoke  ! on the datatype involved first.)A branch used in  L (whose type is parametrised by the source and view types) can be either  or &. The exit conditions specified in  branches should (ideally) be disjoint. Overlapping exit conditions are still allowed for fast prototyping, though  the putback semantics of   will compute successfully as long as the ranges of the branches are disjoint (regardless of whether the exit conditions are specified precisely enough).A  branch contains an inner program, which should update the source such that both the main condition (on both the source and view) and the exit condition (on the source) are satisfied.An W branch contains an adaptation function, which should modify the source such that a  branch is applicable.This is the datatype of BiGUL programs, as a GADT indexed with the source and view types. Most of the types appearing in a BiGUL program should be instances of  to enable error reporting.,Abort computation and emit an error message.vKeep the source unchanged, with the side condition that the view can be completely determined from the source. Use   when the view is a constant.QReplace the source with the view (which should have the same type as the source).When the source and view are both pairs, perform update on the first/second source and view components using the first/second inner program.Rearrange the source into an intermediate form, which is updated by the inner program, and then invert the rearrangement. Instead of using  directly, use   instead, which offers a more intuitive syntax. Note that the inner program should make sure that the updated source still retains the intermediate form (so the inversion can succeed).Rearrange the view into a new one before continuing with the remaining program. To guarantee well-behavedness, the expression should use all variables in the pattern. Instead of using  directly, use d instead, which offers a more intuitive syntax and checks whether all pattern variables are used.When the view is a pair and the second component depends entirely on the first one, discard the second component and continue with the remaining program. *Case analysis on both the source and view.!6Standard composition of bidirectional transformations."RDisplay a programmer-supplied message prefixed with checkpoint:  in error traces.#  !"# ! "# !"       !"111!1None$%&09:;ADLQRTa"$EPattern matching errors, which also explain where the matching fails.%@A constant pattern/expression is matched with a different value.&A & pattern/expression is matched with a  value.'A & pattern/expression is matched with a  value.(TOccurrences of the same variable in an expression are matched with different values.)[A variable that should appear at most once in an expression is however used multiple times.*OA variable that should appear at least once in an expression is however absent.+9The error is on the left of a product pattern/expression.,:The error is on the right of a product pattern/expression.-The error is inside a  pattern/expression..The error is inside a  pattern/expression./5The error is inside a constructor pattern/expression.0Datatype of atomic errors.1 is executed.2When executing Skip f on a source s, the view is not f s.3)The source does not match with a pattern.4'The view does not match with a pattern.5 The inverse rearrangement fails.6!The view cannot be reconstructed.7When executing Dep f _ on a view pair (v, v'), the second component v' is not f v.8No branch in a   statement is applicable.9AAfter adaptation, execution still goes into an adaptative branch.:mAfter execution of a branch, the computed source and view satisfy the main condition of a previous branch.;TAfter execution of a branch, the updated source fails to satisfy the exit condition.<\After execution of a branch, the computed source and view do not satisfy the main condition.=`The main condition is not satisfied by the source and view (and hence the branch is not chosen).>)The branch is adaptive and hence ignored.?uExecution traces, which log the operations executed, intermediate sources and views, and reasons of eventual failure.@)Execution successfully produces a result.A$Execution fails to produce a result.B6An intermediate step with the current source and view.C-An intermediate step with the current source.DInside a branch. *Notes that branch numbering starts from 0.EAll branches fail.&$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI#$%&'()*+,-./0123456789:;<=>?@ABCDEF&?@ABCDEI0123456789:;<=>FH$%&'()*+,-./G$ %&'()*+,-./0123456789:;<=>?@ABCDEFGHINone$%&09:;ADLQRTa JKLMNOPQRS JKLMNOPQRS JKLMNOPQRS JKLMNOPQRSNone$%&09:;ADLQRTaA _ monad with/modulo trace information  the monad laws hold only when the trace component is not considered.TThe putback semantics of a  program.UThe execution trace of a T computation.VThe get semantics of a  program.WThe execution trace of a V computation.TUVWXYZTUVWTUVWTUVWXYZNone$%&09:;ADLQRTa["The unsafe putback semantics of a  program.\The unsafe get semantics of a  program.[\[\[\[\None$%&09:;ADLQRTa view patternsource pattern expression] Generate a  instance for a named datatype so that its constructors can be used in rearranging lambda-expressions. Invoke this function on a datatype T by putting deriveBiGULGeneric ''T@at the top level of a source file (say, after the definition of T). Only simple datatypes and newtypes are supported (no GADTs, for example); type parameters and named fields (record syntax) are supported.1translate all (VarE name) to directions using env^A higher-level syntax for , allowing its first and second arguments to be specified in terms of a simple lambda-expression. The usual way of using ^ is  $(rearrS [| f |]) b :: BiGUL s vwhere  f :: s -> s'# is a simple lambda-expression and b :: BiGUL s' v an inner program._A higher-level syntax for , allowing its first and second arguments to be specified in terms of a simple lambda-expression. The usual way of using _ is  $(rearrV [| f |]) b :: BiGUL s vwhere  f :: v -> v'# is a simple lambda-expression and b :: BiGUL s v' an inner program. In f , wildcard _  is not allowed, and all pattern variables must be used in the body. (This is for ensuring that the view information is fully embedded into the source.)takes a source pattern and produces a tuple pattern consisting of all the variables in the source pattern 1:s:ss -> (() , (s, ss))Example: rearrSV [p| x:xs |] [p| x:xs |] [p| (x,xs) |] [d| x = Replace; xs = rec |] generates a rearrS from the first pattern and the third pattern and a rearrV from the second pattern and the third pattern`A succinct syntax dealing with the frequently occurring situation where both the source and view are rearranged into products and their components further synchronised by inner updates. For example, the program M$(update [p| x:xs |] [p| x:xs |] [d| x = Replace; xs = b |]) :: BiGUL [a] [a][matches both the source and view lists with a cons pattern, marking their head and tail as x and xs3 respectively, and synchronises the heads using Replace' (which is the program associated with x6 in the declaration list) and the tails using some b :: BiGUL [a] [a](. In short, the program is equivalent to ^$(rearrS [| \(x:xs) -> (x, xs) |])$ $(rearrV [| \(x:xs) -> (x, xs) |])$ Replace `Prod` b(Admittedly, it is an abuse of syntax to represent a list of named BiGUL programs in terms of a declaration list, but it is the closest thing we can find that works directly with Template Haskell.)aConstruct a normal branch, for which a main condition on the source and view and an exit condition on the source should be specified. The usual way of using a is -$(normal [| p |] [| q |]) b :: CaseBranch s vwherep :: s -> v -> Bool,q :: s -> Bool, andb :: BiGUL s v, which is the branch body.bA special case of a where the main condition is specified as the conjunction of two unary predicates on the source and view respectively. The usual way of using b is 9$(normalSV [| ps |] [| pv |] [| q |]) b :: CaseBranch s vwhereps :: s -> Bool,pv :: v -> Bool,q :: s -> Bool, andb :: BiGUL s v, which is the branch body.cConstruct an adaptive branch, for which a main condition on the source and view should be specified. The usual way of using c is '$(adaptive [| p |]) f :: CaseBranch s vwherep :: s -> v -> Bool andf :: s -> v -> s#, which is the adaptation function.dA special case of c where the main condition is specified as the conjunction of two unary predicates on the source and view respectively. The usual way of using d is 3$(adaptiveSV [| ps |] [| pv |]) f :: CaseBranch s vwhereps :: s -> Bool,pv :: v -> Bool, andf :: s -> v -> s#, which is the adaptation function.A]^rearranging lambda-expression_rearranging lambda-expression`source pattern view pattern%named updates (as a declaration list)a8main condition (binary predicate on the source and view).exit condition (unary predicate on the source)b5main source condition (unary predicate on the source)1main view condition (unary predicate on the view).exit condition (unary predicate on the source)c8main condition (binary predicate on the source and view)d5main source condition (unary predicate on the source)1main view condition (unary predicate on the view)efg]^_`abcd]^_`abcd;]^_`abcdefgNone$%&09:;ADLQRTajJSkip updating the source when the view is known to be a constant. Same as  Skip . const.kWA nicer notation for applying a branch constructing function to a branch body. Same as .l8Embed a well-behaved pair of transformations into BiGUL.jkljkljkljklk0None$%&09:;ADLQRTam alwaysFail = Fail "always fail"the combinator L will always fail all the transformation, reporting the given error message.get alwaysFail "Please succeed"Left fail: always failput alwaysFail 23 FalseLeft fail: always failn  constSquare = Skip (\s -> s * s)(Skip f) means that in the get direction, the view is fully computed by apply function f to the source. So in the put direction, the update is skipped and the source is unchanged. in the put direction, if (f source) /= view, an error is raised. the view is the square of the source.put constSquare 10 100Right 10put constSquare 10 225Left *** Exception blabla...get constSquare 5Right 25o )repFirst = Replace `Prod` Skip (const ())Rthe example shows a simplest case to chain basic constructors of BiGUL together. M is right associative with priority 1 (0 is the lowest, e.g. $ is 0) To use d, the source and view are assumed to be tuple. the first elements of both tuples are associated by , the second by ."put repFirst (False, 9) (True, ())Right (True,9)get repFirst (True, 3)Right (True,())p CrepFirst' = $(update [p| (x,_) |] [p| (x,()) |] [d| x = Replace |]) This is the o7 example rewritten with syntactic sugar. The syntax is L$(update [p| source-pattern |] [p| view-pattern |] [d| updating-strategy |])Source and view are decomposed by the patterns in the [p| ... |]. In this concrete example, the first elements of the tuple (both in the source and in the viwe) are bound to variable x, and they are sent to the combinator  as arguments by ( x=Replace7) in the [d| ... |] part. anything we want to perform o should be marked as underline(_) in the [p| source-pattern |] and it should not appear in the [d| ... |] part.GThe source-pattern and view-pattern can be very different, for example: 9$([p| Left x : _ |] [p| ((), x) |] [d| x = blabla... |])where the source-pattern stands for a non-empty list of Either type, and we bind variable x to the inner part of the Left constructor. However the view is a tuple, and we bind the second element to x. The rearrangement for source and view is automatically done.q @repFirstV2 = RearrV PVar' (EDir DVar `EProd` EConst ()) repFirstSkip to r- if you want to use the syntactic sugar only.In the previous example, suppose what we really want is that, the view has type a rather than (a,()). In order to do so, we can use , which first rearranges the view into the desired structure, and then uses another BiGUL program to perform the transformation. The usage of  is: 2RearrV (old-pattern) (new-pattern) (bigul-program)6 means there is a variable (a hole to be update), and  is the same as % except that it does not require the Q constraint. In this concrete example, since the view is a single variable, the  old-pattern is . X still means there is a variable. But DVar should be used in the second argument of the . Since there may be many variables in the old-pattern, we need to mark the origin of each variable in the new-pattern: where does it come from. In this concrete example, because there is only one variable in the old-pattern, a & is enough to locate it. Then we use  to make  becomes a direction,  it with a constant ? (). A more complex situation about the new-pattern is in the s example.r 3repFirstV2' = $(rearrV [| \v -> (v,()) |]) repFirstIt is difficult to use primitive combinators, especially when the problem becomes complex. Here we introduce another syntactic sugar: 9$(rearrV [| \old-pattern -> new-pattern |]) bigul-programBWhen rearranging the view, it's possible to duplicate information: ($(rearrV [| \v -> (v,v)|]) bigul-program but it's  not allowed to drop information: G$(rearrV [| \(vl,vr) -> vl |]) bigul-program -- this is WRONGs ErepFirstV3 = RearrS (PVar' `PProd` PVar') (EDir (DLeft DVar)) Replace1The function produces exactly the same result as q,. The difference is that, instead of using 2 to rearrange the view into a tuple, here we use L to rearrange the source into a single value of type a, and then simply use  to update the source. The usage of  is: 2RearrS (old-pattern) (new-pattern) (bigul-program)GThe original source is a tuple, that is to say, there are two variables. So the old-pattern is (PVar' `Prod` PVar'). In the new-pattern, We need to tell BiGUL that, it is the first element of the tuple, i.e. the left element, we want to update. This is achieved by (DLeft DVar). Finally, we convert it into a direction using .t 2repFirstV3' = $(rearrS [| \(l, _) -> l |]) Replace The syntactic sugar version for sK. The usage of the syntactic sugar is basically the same as $(rearrV ...): 9$(rearrS [| \old-pattern -> new-pattern |]) bigul-programu BrepFirstV4 = Dep (const ()) ($(rearrS [| \(l, _) -> l |]) Replace)Yet another version of o=. This artificial example briefly introduces the constructor  , which is rather seldom used. % can be used to add or eliminate information on the view. In this concrete example, since the second element of the view is a unit (()), it can be produced from any existing view v by (const ()), which is equivalent to (v -> const () v). Now we can consider a bidirectional transformation f &($(rearrS [| \(l, _) -> l |]) Replace)ywhich is between source (a,b) and view a only. Then both the transformation f and the function (const ()) are passed to A to finally produce the transformation between (a, b) and (a, ())v  Case [ $(normal [| \(a,b) c -> a <= b && c <= b |] [|\(a,b) -> a <= b |]) $(update [p| (a,_) |] [p| a |] [d| a = Replace |]) , $(normal [| \(a,b) c -> b < a && c < a |] [|\(a,b) -> b < a |]) $(update [p| (_,b) |] [p| b |] [d| b = Replace |]) , $(normal [|\ _ _ -> True|] [|\(a,b) -> False |]) (Fail "the source view are not consistent.") ]Here we introduce the  ( combinator, which is extremely useful.  T resembles the conditional branch in most languages. In this concrete example, the  H combinator enables us to do the following: Suppose the source is (a,b) and the view is c, if (a <= b && c <= b), then we replace a with c; if (b < a && c < a), then we replace b with c; otherwise, the program fails. Because in this case once the minimum element in the source is replaced, it is no longer the minimum element.The general structure for   is: Case [ $(normal [| enteringCond1 :: s -> v -> Bool |] [|exitCond1 :: s -> Bool |]) $ (bx1 :: BiGUL s v) , $(adaptive [| enteringCond1' :: s -> v -> Bool |]) $ (f1 :: s -> v -> s) , ... , $(normal [| enteringCondn :: s -> v -> Bool |] [|exitCond1 :: s -> Bool |]) $ (bxn :: BiGUL s v) , ... , $(adaptive [| enteringCondm' :: s -> v -> Bool |]) $ (fm :: s -> v -> s) ] :: BiGUL s vIt contains a sequence of cases. For each case, it is either normal or adaptive. For the normal case, if the condition is satisfied, a corresponding putback transformation is applied. For the adaptive case, if the condition is satisfied, a function is used to update the source with the view so that for the next step one of the normal cases can be applied. Note that if adaptation does not lead the source and the view to a normal case, an error will be reported at runtime. The example for adaptive branch is in the next example.^Note that $(normal ... ...) takes two predicates. The first one is the entering-condition while the second one is the exit-condition. The predicate for entering-condition is very general, and we can use any function f of type (s -> v -> Bool) to examine the source and view. If the condition is matched, then the BiGUL program after the predicate is executed. If the condition is not satisfied, the next branch is tried. The predicate for exit-condition checks the source only. The exit-condition in different branches should be always NOT overlapped. Eg: (a <= b), (b < a), (False) are not overlapped.VNote: instead of a general function, we can use patterns for predicate. The syntax is: $(normalSV [p| source-pattern |] [p| view-pattern |] [| exitCond |] ) ... $(adaptiveSV [p| source-pattern |] [p| view-pattern |]) For example: @$(normalSV [p| Left _:_ |] [p| [] |] [| exitCond |] )Gstates that the source is a non-empty list with the first element in a LeftR constructor, and the view is an empty list. This feature is heavily used in the | example.OPlease avoid using variables in the pattern-predicate: always use an underline.put replaceMin (2,7) 4 Right (4,7)put replaceMin (2,7) 10.Left fail: the source view are not consistent.get replaceMin (2,7)Right 2w UlensLength def = Case [ $(adaptive [| \s v -> length s /= v |]) (\s v -> let ls = length s in if ls > v then drop (ls - v) s else replicate (v - ls) def ++ s) , $(normal [|\s v -> length s == v |] [| const True |]) (Skip length) ]In this example, the source is any list and the view is the length of the source. Note that The function is not a lens: we should provide the function with a default value to make it a lens. The default value is used to generate new elements and thus expand the source, when the view is greater than the length of the source. If the view is less than the length of the source, the source will be shortened.)Here we introduce the adaptive branch of  %, which takes a predicate (just like  branch), and a function (f :: s -> v -> s) that is used to create a new source. Adaptive branch can be placed anywhere in a  Q. Once the adaptive branch is executed and the new source is created, the whole  h will be re-executed from the first branch. If again an adaptive branch is matched, an error is thrown.zAnother point is that, adaptive branch is chosen in the put direction only. In the get direction, it will never be chosen.put (lensLength 10) [2,2,1] 2 Right [2,1]put (lensLength 10) [2,2,1] 6Right [10,10,10,2,2,1]"get (lensLength undefined) [1..10]Right 10x lensLength' def = emb length p where p = \s v -> let ls = length s in if ls > v then drop (ls - v) s else replicate (v - ls) def ++ snIn fact what lensLength expresses is just that: We have two functions g and p, g is used to do the get (by a / branch), while p is used to do the put (by an W branch). this intention can be expressed in a more simple and modular way: using the z& (embed) function. the definition of z" can be found in the next example.y  (==>) = ($)Imake it more elegant to write ($). Later we may use (==>) instead of ($).z |emb g p = Case [ $(normal [| \s v -> g s == v |] [p| _ |]) ==> Skip g , $(adaptive [| \s v -> True |]) ==> p ]<emb g p: invoke g to do the get, and invoke p to do the put.{ +lensSucc = emb (flip (+) 1) (\_ v -> v - 1) Sometimes z is useful. For instance, Int is a primitive datatype without any constructor in Haskell, and cannot be manipulated in a way like list in ReaarV or p. For list, we can write (x:xs) -> (x:x:xs) using its constructor. But we cannot decompose Int. Making use of z, we can manipulate basic operations for Int, whose well-behavedness should be proved by hand. (But here, the well-behavedness is easily seen.)put lensSucc 0 10Right 9get lensSucc 8Right 9|  naiveMap b = Case [ $(normalSV [p| _:_ |] [p| _:_ |] [p| _:_ |]) ==> $(update [p| x:xs |] [p| x:xs |] [d| x = b; xs = naiveMap b |]) , $(adaptiveSV [p| _:_ |] [p| [] |] ) (\_ _ -> []) , $(normalSV [p| [] |] [p| _:_ |] [| const False |]) ==> (Fail "length of the view should be less than that of the source.") , $(normalSV [p| [] |] [p| [] |] [p| [] |]) ==> $(update [p| [] |] [p| [] |] [d| |]) ]A naive map function, which takes a BiGUL program and yields another BiGUL program working on list. The first branch deals with recursive condition. The second branch handles the boundary conditions where the source list is longer than the view list: drop all the remaining elements in the source list and thus make it an empty list. The third branch will throw an error when the view list is longer than the source list. The last branch is the termination condition: both the source and view reach the empty constructor.((For the sake of completeness.) In fact bt means that we use separate condition for source and view. So we can still use a general function in the predicate: P$(normalSV [| \s -> case s of _:_ -> True; _ -> False |] [p| _:_ |] [p| _:_ |]))put (naiveMap lensSucc) [1,2,3,4] [7,8,9] Right [6,7,8]4get (naiveMap (lensLength undefined)) ["123", "xyz"] Right [3,3]1get (naiveMap replaceMin) [(3,9), (-2,10),(10,2)]Right [3,-2,2]} compose = Compose1The last combinator we are going to introduce is !J, which takes two BiGUL programs and behaves like "function composition".Given two BiGUL programs, f :: BiGUL a b, g :: BiGUL b cwe have f `Compose` g :: BiGUL a c'In the get direction, the semantics of get (f `Compose` g) s is: (suppose the function V and T6 always return a value rather than a value wrapped in .) get g (get f s)'In the put direction, the semantics of put (f `Compose` g) s v is a little bit complex: put f s (put g (get f s) v)Let us make it more clear: /let a = get f s b = put g a v in put f s bTCheck the type of these transformations by yourself will help you understand deeper.Let us try some examples:Qput ((naiveMap replaceMin) `compose` (naiveMap lensSucc)) [(1,-1),(-2,2)] [-8, 1]Right [(1,-9),(0,2)]Iget ((naiveMap replaceMin) `compose` (naiveMap lensSucc)) [(1,-1),(-2,2)] Right [0,-1]~The last example in this tutorial is a simple map-map fusion. It makes the composition of two map functions run more efficiently, compared to using ! combinator.kIn the get direction, (get (f `Compose` g)) traverse the list twice, while (get (mapFusion f g)) traverse the list only once. And in the put direction, (put f `Compose` g) traverse the two lists up to five times (get counts up once, two put count up four times, since a put takes two lists as argument), while (put mapFusion f g) traverses the lists only twice.&Compare the following result (in GHCI) t1 :: Int t1 = last $ fromRight $ put (naiveMap lensSucc `Compose` naiveMap lensSucc) [1..100000] [2..20001] t2 :: Int t2 = last $ fromRight $ put (mapFusion lensSucc lensSucc) [1..100000] [2..20001] fromRight (Right x) = xt119999(1.24 secs, 512,471,456 bytes)t219999(0.23 secs, 122,920,792 bytes)8More examples can be found in the list library of BiGUL.mnopqrstuvwxyz{|}~mnopqrstuvwxyz{|}~mnopqrstuvwxyz{|}~mnopqrstuvwxyz{|}~ None$%&09:;ADLQRTa~List alignment. Operating only on the sources satisfying the source condition, and using the specified matching condition,  finds for each view the first matching source that has not been matched with previous views, and updates the source using the inner program. If there is no matching source, one is created using the creation argument  after creation, the created source should match with the view as determined by the matching condition. For a source not matched with any view, the concealment argument is applied  if concealment computes to Nothing7, the source is deleted; if concealment computes to Just s', where s'G should not satisfy the source condition, the source is replaced by s'.source conditionmatching condition inner programcreation concealment !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijdfk lmnopqrstu vwxyz{|}~vw     "BiGUL-1.0.1-2uZtCIbveLPAFkkfAGSgpQGenerics.BiGULGenerics.BiGUL.ErrorGenerics.BiGUL.PatternMatchingGenerics.BiGUL.Interpreter!Generics.BiGUL.Interpreter.UnsafeGenerics.BiGUL.THGenerics.BiGUL.LibGenerics.BiGUL.Lib.HuStudiesGenerics.BiGUL.Lib.List GHC.InOutderiveBiGULGenericsskiprearrSrearrV GHC.GenericsGenericExprEDirEConstEProdELeftERightEIn DirectionDVarDLeftDRightVarPatPVarPVar'PConstPProdPLeftPRightPIn CaseBranchNormalAdaptiveBiGULFailSkipReplaceProdRearrSRearrVDepCaseCompose Checkpoint $fShowVarPatErrorPEConstantMismatchPELeftMismatchPERightMismatchPEIncompatibleUpdatesPEMultipleUpdatesPEValueUnrecoverablePEProdLPEProdRPELeftPERightPEIn BiGULErrorBEFailBESkipMismatchBESourcePatternMismatchBEViewPatternMismatchBEInvRearrFailedBEViewRecoveringFailedBEDependencyMismatchBECaseExhaustedBEAdaptiveBranchRevisitedBEPreviousBranchMatchedBEExitConditionFailedBEPostVerificationFailedBEBranchUnmatchedBEAdaptiveBranchMatched BiGULTrace BTSuccessBTErrorBTNextSVBTNextSBTBranch BTBranchesindent$fShowPatError$fShowBiGULError$fShowBiGULTrace modifyError deconstruct constructretrieveevaluneval unevalDirfromContainerVfromContainerSemptyContainerputputTracegetgetTrace$fMonadBiGULResult$fApplicativeBiGULResult$fFunctorBiGULResultderiveBiGULGenericupdatenormalnormalSVadaptive adaptiveSV $fExpOrPatQ $fExpOrPatQ0 $fShowPatTag $fShowConTag $fDataConTag==>emb alwaysFail constSquarerepFirst repFirst' repFirstV2 repFirstV2' repFirstV3 repFirstV3' repFirstV4 replaceMin lensLength lensLength'lensSuccnaiveMapcompose mapFusionalign ToFromRepfromReptoRepFFlattenInOutinnout$fInOuta$fToFromRep:*:$fToFromRep:+: $fToFromRepM1 $fToFromRepK1 $fToFromRepU1base Data.EitherEitherGHC.ShowShowLeftRight BiGULResultGHC.BaseMayberunBiGULResult catchBind errorResult modifyTrace embedEither incrBranchNoaddCurrentBranchTrace putWithTrace getCaseBranchputCaseCheckDiversionputCaseWithAdaptationputCase getWithTracegetCase fromRightRTagSTagETag rearrangeExpmkProdPatFromSrearrSVExpOrPattoExp ErrorMessageValueConstructorTypeConstructor NamespacePatTagConTagLR astNamespacecontag lookupName lookupNamesconstructorsToSumconstructorToProductconstructorToPatAndBody zipWithLRs consToEnvconstructFuncFromClauseconstructFuncToClausegenerateSelectorNamesgenerateSelectorDataDgenerateSelectorDataTypegenerateSelectorDataType'generateSelectorInstanceDecgenerateSelectorInstanceDec'generateTypeVarsType constructLRs lookupLRslookupRecordLengthlookupRecordFieldmkConstrutorFromLRsmkPat mkEnvForRearrsplitDataAndConmkBodyExpForRearrrearr' getAllVars mkExpFromPat mkExpFromPat' toProductmkProdPatFromSHelpermkEnvForUpdatepatCond nameAdaptive nameNormalpatLambdaToPred$ghc-prim GHC.ClassesEq