ed`H/      !"#$%&'()*+,-.Safe@"A memoization class. An instance  T for some type T means that that . method can memoize for parameters of type T.None@ To derive G instances for the given data types. In the simplest usage, to derive " for an algebraic datatype named T, write:  deriveMemoizable ''T -This assumes that all the type parameters of T0 that are not annotated with a kind other than * should be listed as requiring P instances in the instance context. For example, given a data type declared as ! data T a (b :: * -> *) c = ... %the generated instance will look like  instance ( a,  c) =>  (T a b c) where ... 0For more precise control over the context, use . N.B.: The TemplateHaskell: language extension must be enabled to use this function.Like 2 but takes a second argument, which is a list of /s to specify which type parameters of the type should be mentioned in the context. For example, given the same definition for T as above, we can write " deriveMemoizableParams ''T [3]  to leave the first parameter of TC out of the context and show only the third, yielding the instance  instance  c =>  (T a b c) where ...  N.B.: The TemplateHaskell: language extension must be enabled to use this function.In cases where neither  nor  can figure out the right context for an instance declaration, one can declare the instance manually and use this function to derive the method body for ). For example, suppose that a data type T is defined as:  data T a b = T (a -> Bool) b For T a b to be memoizable,  a -> BoolA must be, and based on the instance for '(->)', this means that a must satisfy 0 and 1, so ) cannot build the right context for the # instance. Instead, one can write:  instance (1 a, 0 a,  b) => 2 (T a b) where memoize = $(deriveMemoize ''T) 2pThe main entry point delegates to check given type name, renames type parameters, and generates the instance.3QGiven the type name for the requested instance, checks if it corresponds to a data or newtyper, and if so, returns the name, a list of its parameters, and a list of constructor names with their arities.4Given a list, produces a list of nicely printable, distinct names. Used so that instances print with nice parameters names, like ' instance Memoizable (T a b c) where  instead of 5 instance Memoizable (T a[1] b[2] c32424534) where 5Build the type class instance context, give the necessary information to select which parameters to include. If the first argument is Just ixs, then there should be  instances for exactly those parameters, by index, in the context. Otherwise, choose the parameters that have no explicit kind from the list of binders. The third argument gives the actual type variable names to use.6 Build the G instance head for the given type name and parameter type variables.7 Build the  method. The form of  is always  memoize f = lookup where cache1 = memoize $ x1 -> ... memoize $ x(a1) -> f (C1 x1 ...) ... cacheN = memoize $ x1 -> ... memoize $ x(aN) -> f (CN x1 ...) lookup (C1 x1 ...) = cache1 x1 ... ... lookup (CN xN ...) = cacheN xN ... where C1 ... CN, are the constructors of the data type and aj is the arity of constructor Cj.:In this method, we allocate fresh names for the parameter f , the lookup function, and the N8 caches. We then delegate to build the definitions of look and the caches.8Build the body of the , method, as described in the comment above 79UBuild the look function by building a clause for each constructor of the datatype.:Build a lookup clause for one constructor. We lookup a value by matching that constructor and then passing its parameters to the cache for that constructor.;Build the definition of a cache for the given constructor. We do this by binding the cache name to a cascading sequence of memoizations for each component in the constructor's arity.<Given the remaining arity to memoize, the name of the function to memoize, and the accumulated parameter so far, build the memoization chain.23456789:;<23456789:;<None2@IMemoize a two argument function!Memoize a three argument function Memoize a four argument function Memoize a five argument function Memoize a six argument function !Memoize a seven argument function <Memoizes the least fixed point of a function. This is like u, but it passes the fixed function a memoized version of itself, so this memoizes using all recursive calls as well. Two argument version of  . Three argument version of  .Four argument version of  .Five argument version of  .Six argument version of  .Seven argument version of  .6Give a one-argument function whose argument satisfies =J, this memoizes the function such that the argument is shown (using >l) only when the function has to be applied, as opposed to when the answer is available in the memo cache.?JA positive integer cache is represented as a little-ending bitwise trie@dAn integer cache stores a value for 0 and separate caches for the positive and negative integers.A For finite /S-like types, we use a balanced binary search tree indexed to every element from B to C#:Can be used to memoize over any "finite" type satisfying 1 and 0]. This builds a binary search tree, treating the memoized type as isomorphic to a range of /&, so it will be only as efficient as D, E, F, and G.UThis can be used to make instances for finite types. For example, the instances for / and H are declared as: q instance Memoizable Int where memoize = memoizeFinite instance Memoizable Char where memoize = memoizeFinite C  !"IJKLMNO?@PQRSTUVWXYZ[\A]^#_`abc$%&'() # #6  !"IJKLMNO?@PQRSTUVWXYZ[\A]^#_`abc$%&'()d      !"#$%&'()*+,-./0123456789:89;<=>?@ABCDEF8GH8IJKLM89N89O89P89Q89R89S56TUUVWXYZL[\]^^_`abcdefghijklm"memoize-0.8-8sFGld3EJwq3wWBL9C0bnnData.Function.MemoizeData.Function.Memoize.ClassData.Function.Memoize.TH Data.Functionfix MemoizablememoizederiveMemoizablederiveMemoizableParams deriveMemoizememoize2memoize3memoize4memoize5memoize6memoize7memoFixmemoFix2memoFix3memoFix4memoFix5memoFix6memoFix7 traceMemoize$fMemoizable()$fMemoizableBool$fMemoizableOrdering$fMemoizableMaybe$fMemoizableEither$fMemoizable[]$fMemoizable(,)$fMemoizable(,,)$fMemoizable(,,,)$fMemoizable(,,,,)$fMemoizable(,,,,,)$fMemoizable(,,,,,,)$fMemoizable(,,,,,,,)$fMemoizable(,,,,,,,,)$fMemoizable(,,,,,,,,,)$fMemoizable(,,,,,,,,,,) memoizeFinite$fMemoizable(->)$fMemoizableChar$fMemoizableInt$fMemoizableFinite$fMemoizableInteger$fMemoizable(,,,,,,,,,,,)$fFunctorBinaryTreeCache$fFunctorIntegerCache $fEqFinite$fBoundedFinite $fEnumFiniteghc-prim GHC.TypesIntbaseGHC.EnumBoundedEnumderiveMemoizable' checkName freshNames buildContext buildHeadbuildMethodDecbuildMethodExp buildLookupbuildLookupClause buildCache composeMemosGHC.ShowShow Debug.Tracetrace PosIntCache IntegerCache theFinitesminBoundmaxBoundtoEnumfromEnumsuccpredChar FunctionCachefcNilfcConsFiniteToFinite fromFiniteicZero icNegative icPositiveBinaryTreeCachebtValuebtLeftbtRight theIntegers thePosInts integerLookup posIntLookup finiteLookup meanFinitefunctionLookup theFunctions_fib_isNot _countTrue