úÎ!oul%4      !"#$%&'()*+,-./0123Safe @APgj…+pattern-matcher Computes the ¤ for a given column. It may use the entire pattern matrix but it is also given the index of the column, the expression being matched and the column being matched.pattern-matcher°Combine two heuristics: compute an initial score with the first heuristic and, if several columns have obtained the same score, use the second heuristic to choose among them.pattern-matcher#The index of the column of patternspattern-matcher1Gathers all the anomalies present in a matching. 4' indicating the absence of an anomaly. pattern-matcherMA decision tree can be thought of as a cascade of switches, matching on the tagˆ of expressions and subexpressions until reaching a result. They map fairly naturally to constructs in low level languages, such as C. pattern-matcher†Pattern-matching failure, with a list of all the patterns that aren't matched. The list is lazily generated and may be infinite for tags with infinite ranges. pattern-matcherPattern-matching success pattern-matcherBranching on an tag expression pattern-matcher~The identifiers bound when reaching this leaf. The list of bindings is in the order of matching, as given by the heuristics.pattern-matcher.The result obtained when arriving at this leafpattern-matcherThe expression whose tag is being scrutinisedpattern-matcherSBranches to follow based on specific tags. Any expression not caracterized by any tag' will fall back to the default branch.pattern-matcher%Branch to follow if the expression's tagQ is not present in the set of branches above. This branch may be absent if all tags are present in the pattern-matcherPBinding of an identifier to an expression. Bindings of wildcards are conserved.pattern-matcher1Encodes the selection of a subexpression given a tag.pattern-matcherAn untouched expressionpattern-matcher e t n selects the n+1-th subexpression in e assuming e is caracterized by tag tM. Such an expression will only be generated after it has been checked that e has indeed tag t. For example, Sel (e :: e') _::_ 1!, would select the second field e :: e', in this case e'.pattern-matcheroCarries the range of tags that could have been used in this pattern and, potentially, an identifier to bound.pattern-matcher AsSkel p i matches if p matches and binds i4 to the result of the expression it matches againstpattern-matcher:A generic description of a constructor pattern, made of a tag and subpatterns. pattern-matcher.The range of tags a given tag could have had. t! should always be an element of  tagRange t. In other words: elem t (tagRange t) == TrueThe range of a tagÿN is used to generate missing patterns in non-exhaustive matches. It might be interesting to consider the order the range is given in, to improve the quality of error messages. For instance, if one allows pattern-matching on integers, instead of simply giving the range [minBound..maxBound], it could be better to give the range "[0..maxBound] ++ [-1,-2..minBound]F (or a range alternating positive and negative integers, starting at 0() could help generate simpler messages.!pattern-matcherThe range of the tagHs that can appear in all the subfields of a constructor with the given tag.Example Consider the _:_ tag for patterns of type [Bool]H in Haskell. This pattern has two subpatterns, the head can be either True or False, while the tail can be either [] or _:_. Thus !$ would simply be, in pseudo-Haskell: ([[trueTag, falseTag], [nilTag, consTag]]#pattern-matcherSmart constructor for . 5.s that the number of subpatterns matches the tag 's arity.6pattern-matcher)Extract the range of tags for a skeleton.7pattern-matcher-The arity of a constructor associated with a tag2. Computed as the length of the list returned by !8pattern-matcher%The simplest constructor for a given tag', where all subpatterns are wildcards.9pattern-matcher1Compile a matrix of patterns into a decision tree$pattern-matcherBCompiles a matching to a decision tree, using the given heuristic.%pattern-matcherSimplified version of $:, that simply gathers the anomalies of the decision tree.&pattern-matcher_Combine a list of heuristics from left-to-right, defaulting to using no heuristic. Defined as foldr Combine noHeuristic.'pattern-matcher‘This heuristic favours columns whose top pattern is a generalized constructor pattern. If the first pattern is a wildcard, the heuristic gives 0 and 1 otherwise.(pattern-matcherOThis heuristic favours columns with the least number of wildcard patterns. If v(i)& is the number of wildcards in column i, then -v(i) is the score of column i.)pattern-matcher¾Favours columns resulting in smaller switches. The score of a column is the number of branches of the switch resulting of the compilation (including an eventually default branch), negated.*pattern-matcherAThe sum of the arity of the constructors of this column, negated.+pattern-matcherPThe score is the number of children of the emitted switch node that are leaves.,pattern-matcher?This heuristic favours columns that lead to fewer rows to test.:pattern-matcherReturns ; if column i is needed for row j in the matrix P-. This is the case if: the pattern at column i and row j: is a constructor pattern xor if it's a wildcard but row j of P[i] is useless. Row j of P[i]7 is useless if the patterns above it form a signature.-pattern-matcher6The score is the number of output needing this column..pattern-matcherBThe score is the number of consecutive outputs needing the column./pattern-matcherA cheaper version of .F, where a pattern counts in the score if it is a constructor pattern.0pattern-matcher8Leaves the column in the same order by giving the score -i to column i.1pattern-matcher5Reverse the order of the columns by giving the score i to column is. It can be useful in combination with another heuristic to reverse the left-to-right bias of this implementation.2pattern-matcher³This heuristic is called a pseudo-heuristic as it doesn't operate on the patterns but on the expression. It is most useful as a last resort heuristic in combination with others.$pattern-matcher1The heuristic to use to resolve ambiguous choicespattern-matcher1A way to decompose the language's patterns into _etons. Producing a list allows to account for or-patterns. They are tested from left to right.pattern-matcher The expression being scrutanizedpattern-matcherdThe list of patterns to match on with the output associated. Patterns are tried from left to right.3 " !#$%&'()*+,-./0124$%""# ! &'()*+,-./012<      !"#$%&'()*+,-./01234536789:;<=>?@-pattern-matcher-0.1.0.1-Jed5oiF6qdKLAlu6DdbdJLanguage.Pattern.Compiler HeuristicScoreCombineIndex AnomaliesredundantPatternsunmatchedPatternsDecTreeFailLeafSwitch leafBindingsleafOut leafRedundantswitchOnswitchBranchesswitchCatchAllBinding:=SelectNoSelSelSkelWildSkelConsSkelAsSkelConsconsTag consPayloadIsTagtagRangesubTagsconsmatch anomalies seqHeuristicsfirstRow smallDefaultsmallBranchingFactorarityleafEdgefewerChildRule neededColumns neededPrefixconstructorPrefix noHeuristicreverseNoHeuristicshorterOccurence $fShowBindingbase GHC.MaybeNothingGHC.Baseassert skelRangetagArity defaultCons compileMatrixusefulghc-prim GHC.TypesTrue