úÎĒk˜!U      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRST(C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalportable Safe-Inferred a p w replaces the free variable a with p in w.9substitute "hello" ["goodnight","Gracie"] ["hello","!!!"]["goodnight","Gracie","!!!"] a b w replaces a free variable a with another free variable b in w.5substituteVar "Alice" "Bob" ["Alice","Bob","Charlie"]["Bob","Bob","Charlie"]jIf a term has no free variables, you can freely change the type of free variables it is parameterized on. closed [12]Nothing closed ""Just [] :t closed ""closed "" :: Maybe [b]$A closed term has no free variables. isClosed []TrueisClosed [1,2,3]False(C) 2012-2015 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalportable Safe-Inferred1 Instances of # generate left modules over monads.2This means they should satisfy the following laws: m  U "a m m  (ŧ x !’ k x V h) "a (m  k)  h –This guarantees that a typical Monad instance for an expression type where Bound instances appear will satisfy the Monad laws (see doc/BoundLaws.hs).If instances of  are monad transformers, then m  f "a m V W X f@ implies the above laws, and is in fact the default definition.ĄThis is useful for types like expression lists, case alternatives, schemas, etc. that may not be expressions in their own right, but often contain expressions.Perform substitutionIf t is an instance of  MonadTransM and you are compiling on GHC >= 7.4, then this gets the default definition: m  f = m V W X fA flipped version of (). () = Y () Z[\]^_`ab Z[\]^_`ab(C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalportable Trustworthy+0"I am not a number, I am a  free monad!"A  b a+ is a variable that may either be "bound" (  ) or "free" ().H(It is also technically a free monad in the same near-trivial sense as c.)this is a free variable this is a bound variable This provides a Prism that can be used with lens library to access a bound .   :: Prism (Var b a) (Var b' a) b b'@ This provides a Prism that can be used with lens library to access a free .   :: Prism (Var b a) (Var b a') a a'@  d efghijklmnopqrstuvwxyz{|    d efghijklmnopqrstuvwxyz{|(C) 2012-2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalportable Trustworthy*+3HM   b f a is an f$ expression with bound variables in b, and free variables in aaWe store bound variables as their generalized de Bruijn representation in that we're allowed to W (using n) an entire tree rather than only succ individual variables, but we're still only allowed to do so once per  . Weakening trees permits O(1)^ weakening and permits more sharing opportunities. Here the deBruijn 0 is represented by the   constructor of , while the de Bruijn }: (which may be applied to an entire tree!) is handled by .6NB: equality and comparison quotient out the distinct  placements allowed by the generalized de Bruijn representation and return the same result as a traditional de Bruijn representation would.FLogically you can think of this as if the shape were the traditional  f (Var b a), but the extra f a inside permits us a cheaper W.9Capture some free variables in an expression to yield a   with bound variables in b:m + Data.List$abstract (`elemIndex` "bar") "barry"Scope [B 0,B 1,B 2,B 2,F "y"]Abstract over a single variableabstract1 'x' "xyz"Scope [B (),F "y",F "z"]0Enter a scope, instantiating all bound variables:m + Data.ListLinstantiate (\x -> [toEnum (97 + x)]) $ abstract (`elemIndex` "bar") "barry""abccy"Enter a  * that binds one variable, instantiating it+instantiate1 "x" $ Scope [B (),F "y",F "z"]"xyz"* quotients out the possible placements of  in  x by distributing them all to the leaves. This yields a more traditional de Bruijn indexing scheme for bound variables.Since,  X  "a ~ we know that  X  X  "a and therefore ( . ) is idempotent.DConvert from traditional de Bruijn to generalized de Bruijn indices.#This requires a full tree traversal;Perform substitution on both bound and free variables in a  .;Return a list of occurences of the variables bound by this  .1Perform a change of variables on bound variables.IPerform a change of variables, reassigning both bound and free variables.>Perform a change of variables on bound variables given only a  instance A version of ) that can be used when you only have the  instanceMObtain a result by collecting information from both bound and free variablesMObtain a result by collecting information from both bound and free variables€ the bound variables in a  .? both the variables bound by this scope and any free variables. ,mapM_ over the variables bound by this scope!A ' that can be used when you only have a  instance"&Traverse both bound and free variables#&Traverse both bound and free variables$'mapM over both bound and free variables%A #' that can be used when you only have a  instance(This allows you to ‚ a  .)#This is a higher-order analogue of .+9instantiate bound variables using a list of new variables,#Lift a natural transformation from f to g into one between scopes.ƒSThe monad permits substitution on free variables, while preserving bound variables„…; is provides a list (with duplicates) of the free variables5  !"#$%&'()*+,†‡ˆ‰Š‹ŒŽ‘’“”•ƒ–—„˜  !"#$%&'()*+,  !"#$%&',(*)+3  !"#$%&'()*+,†‡ˆ‰Š‹ŒŽ‘’“”•ƒ–—„˜(C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalportable Trustworthy+0-We track the choice of - n% as a forgettable property that does not affect the result of (™) or š.)To compare names rather than values, use ( š /) instead./ Extract the /.0This provides an Iso+ that can be used to access the parts of a -. 0 :: Iso (- n a) (- m b) (n, a) (m, b) 1-Abstraction, capturing named bound variables.2Abstract over a single variable3fEnter a scope, instantiating all bound variables, but discarding (comonadic) meta data, like its name4Enter a  3 that binds one (named) variable, instantiating it. 4 = !-./01234›œžŸ ĄĒĢĪĨͧĻĐŠŦŽ­ŪŊ°ąēģ-./01234-.0/1234 -./01234›œžŸ ĄĒĢĪĨͧĻĐŠŦŽ­ŪŊ°ąēģ(C) 2013 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalportable Trustworthy*+3HM55 b f a is an f$ expression with bound variables in b, and free variables in a5This implements traditional de Bruijn indices, while   + implements generalized de Bruijn indices.[These traditional indices can be used to test the performance gain of generalized indices.While this type 5 is identical to   3 this module focuses on a drop-in replacement for   .WAnother use case is for syntaxes not stable under substitution, therefore with only a ī instance and no  instance.89Capture some free variables in an expression to yield a 5 with bound variables in b:m + Data.List$abstract (`elemIndex` "bar") "barry"Scope [B 0,B 1,B 2,B 2,F 'y']9Abstract over a single variableabstract1 'x' "xyz"Scope [B (),F 'y',F 'z']:0Enter a scope, instantiating all bound variables:m + Data.ListLinstantiate (\x -> [toEnum (97 + x)]) $ abstract (`elemIndex` "bar") "barry""abccy";Enter a 5* that binds one variable, instantiating it+instantiate1 "x" $ Scope [B (),F 'y',F 'z']"xyz"== is just another name for 7 and is exported to mimick  . In particular no  constraint is required.>> is just another name for 5 and is exported to mimick . In particular no  constraint is required.?;Perform substitution on both bound and free variables in a 5.@;Return a list of occurences of the variables bound by this 5.A1Perform a change of variables on bound variables.BIPerform a change of variables, reassigning both bound and free variables.C>Perform a change of variables on bound variables given only a  instanceD A version of B) that can be used when you only have the  instanceEMObtain a result by collecting information from both bound and free variablesFMObtain a result by collecting information from both bound and free variablesG€ the bound variables in a 5.H? both the variables bound by this scope and any free variables.I,mapM_ over the variables bound by this scopeJA H' that can be used when you only have a  instanceK&Traverse both bound and free variablesL&Traverse both bound and free variablesMThis allows you to ‚ a 5.N#This is a higher-order analogue of .O9instantiate bound variables using a list of new variablesQ'mapM over both bound and free variablesRA L' that can be used when you only have a  instanceĩSThe monad permits substitution on free variables, while preserving bound variablesķ…; is provides a list (with duplicates) of the free variables556789:;<=>?@ABCDEFGHIJKLMNOPQRST·ļđšŧž―ūŋĀÁÂÃÄÅÆĩĮČķÉ 56789:;<=>?@ABCDEFGHIJKLMNOPQRST 56789:;=>?@ABCDEFGHIJKLQRST<MPNO356789:;<=>?@ABCDEFGHIJKLMNOPQRST·ļđšŧž―ūŋĀÁÂÃÄÅÆĩĮČķÉ (C) 2012 Edward Kmett BSD-style (see the file LICENSE)Edward Kmett <ekmett@gmail.com> experimentalportable Safe-Inferred   Ę     !"#$%&'()*+,-./01234567789:;<=  6  !"#$%&'()*+,-2354./01>?@>?ABCD>?E>?FGHIJKLMNO>PQRSTUVWXYZ[\]^_`abcdefghij>kl>?m>?n>op>qrstuvw>oxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽŒ‘’“”•–—˜™š›œžŸ ĄĒĢĪĨͧĻ>?Đvwyz{|}~€‚ƒ„…†‡ˆ‰Š‹Š bound-1.0.6 Bound.Term Bound.Class Bound.Var Bound.Scope Bound.NameBound.Scope.Simple Data.FunctiononBoundScopeControl.Monad.TransEitherT fromScopetoScope substitute substituteVarclosedisClosed>>>==<<<VarFBunvar_B_Funscopeabstract abstract1 instantiate instantiate1splatbindingsmapBoundmapScope liftMBound liftMScope foldMapBound foldMapScopetraverseBound_traverseScope_ mapMBound_ mapMScope_ traverseBound traverseScope mapMBound mapMScopeserializeScopedeserializeScopebitraverseScopetransverseScopebitransverseScopeinstantiateVars hoistScopeNamename_Name abstractName abstract1NameinstantiateNameinstantiate1NamebaseGHC.Basereturn>>=transformers-0.3.0.0Control.Monad.Trans.Classlift.flip$fBoundWriterT $fBoundStateT$fBoundReaderT $fBoundRWST $fBoundMaybeT $fBoundListT$fBoundIdentityT $fBoundErrorT $fBoundContT Data.EitherEither distinguisher $fRead1Var $fShow1Var $fOrd1Var$fEq1Var $fRead2Var $fShow2Var $fOrd2Var$fEq2Var$fBitraversableVar$fBifoldableVar$fBifunctorVar $fMonadVar$fApplicativeVar$fTraversableVar $fFoldableVar $fFunctorVar$fSerializeVar $fBinaryVar $fSerialVar $fSerial1Var $fSerial2Var $fHashableVar$fHashable1Var$fHashable2VarGHC.EnumsuccidMonad Data.Foldable traverse_Data.Traversabletraverse bifunctors-5Data.Bitraversable bitraverse $fMonadScope$fFoldableScopetoList$fSerializeScope $fBinaryScope $fSerialScope$fSerial1Scope$fHashableScope$fHashable1Scope $fBoundScope $fRead1Scope $fReadScope $fShow1Scope $fShowScope $fOrd1Scope $fOrdScope $fEq1Scope $fEqScope$fMonadTransScope$fApplicativeScope$fTraversableScope$fFunctorScopeghc-prim GHC.Classes==compare$fSerializeName $fBinaryName $fSerialName $fSerial1Name $fSerial2Name $fRead2Name $fShow2Name $fOrd2Name $fEq2Name $fRead1Name $fShow1Name $fOrd1Name $fEq1Name $fComonadName$fBitraversableName$fBifoldableName$fBifunctorName$fTraversableName$fFoldableName $fFunctorName $fOrdName$fHashableName$fHashable1Name$fHashable2Name$fEqNameFunctor