úÎeúa      Safe-Inferred"A memoization class. An instance  T for some  type T means that that  method can memoize for  parameters of type T. None To derive % 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 T that are not " annotated with a kind other than * should be listed as requiring  8 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 ... /For more precise control over the context, use  .  N.B.: The TemplateHaskell+ language extension must be enabled to use  this function. Like . but takes a second argument, which is a list  of 9s to specify which type parameters of the type should be G 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 T 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 E 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 -> Bool must be, and based on the  instance for '(->)', this means that a must satisfy   and , so  cannot build the right  context for the $ instance. Instead, one can write:   instance ( a,  a,  b) =>   (T a b) where  memoize = $(deriveMemoize ''T) FThe main entry point delegates to check given type name, renames type + parameters, and generates the instance. =Given the type name for the requested instance, checks if it  corresponds to a data or newtype, and if so, returns the name, B a list of its parameters, and a list of constructor names with  their arities. CGiven a list, produces a list of nicely printable, distinct names. A Used so that instances print with nice parameters names, like   ( instance Memoizable (T a b c) where  instead of   instance Memoizable (T a[1] b[2] c32424534) where :Build the type class instance context, give the necessary B information to select which parameters to include. If the first  argument is Just ixs, then there should be  instances D for exactly those parameters, by index, in the context. Otherwise, ; choose the parameters that have no explicit kind from the D list of binders. The third argument gives the actual type variable  names to use.  Build the ' instance head for the given type name ! and parameter type variables.  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 N$ caches. We then delegate to build  the definitions of look and the caches. Build the body of the % method, as described in the comment  above  BBuild the look function by building a clause for each constructor  of the datatype. >Build a lookup clause for one constructor. We lookup a value C by matching that constructor and then passing its parameters to # the cache for that constructor. BBuild the definition of a cache for the given constructor. We do = this by binding the cache name to a cascading sequence of 5 memoizations for each component in the constructor' s arity. !BGiven the remaining arity to memoize, the name of the function to < memoize, and the accumulated parameter so far, build the  memoization chain.  ! !None Memoize 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  ., but it passes the fixed function a memoized H 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 ", E this memoizes the function such that the argument is shown (using  #/) only when the function has to be applied, as > opposed to when the answer is available in the memo cache. $CA positive integer cache is represented as a little-ending bitwise  trie %BAn integer cache stores a value for 0 and separate caches for the # positive and negative integers. & For finite 2-like types, we use a balanced binary search tree ! indexed to every element from ' to (  Can be used to memoize over any finite type satisfying   and .. This builds a binary search tree, treating / the memoized type as isomorphic to a range of , so it will be  only as efficient as ), *, +, and ,. FThis can be used to make instances for finite types. For example, the  instances for  and - are declared as:  9 instance Memoizable Int where memoize = memoizeFinite : instance Memoizable Char where memoize = memoizeFinite C ./0123456789:;<=>?@ABCD$%EFGHIJKLMNOPQ&RSTUVWXYZ[\]^  6 ./0123456789:;<=>?@ABCD$%EFGHIJKLMNOPQ&RSTUVWXYZ[\]^_      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJJKLMNO1PQRSSTUVWXYZ[\]^_`abcdefgh memoize-0.6Data.Function.MemoizeData.Function.Memoize.ClassData.Function.Memoize.TH Data.Functionfix MemoizablememoizederiveMemoizablederiveMemoizableParams deriveMemoizememoize2memoize3memoize4memoize5memoize6memoize7memoFixmemoFix2memoFix3memoFix4memoFix5memoFix6memoFix7 traceMemoize memoizeFiniteghc-prim GHC.TypesIntbaseGHC.EnumBoundedEnumderiveMemoizable' checkName freshNames buildContext buildHeadbuildMethodDecbuildMethodExp buildLookupbuildLookupClause buildCache composeMemosGHC.ShowShow Debug.Tracetrace PosIntCache IntegerCache theFinitesminBoundmaxBoundtoEnumfromEnumsuccpredChar$fMemoizable()$fMemoizableBool$fMemoizableOrdering$fMemoizableMaybe$fMemoizableEither$fMemoizable[]$fMemoizable(,)$fMemoizable(,,)$fMemoizable(,,,)$fMemoizable(,,,,)$fMemoizable(,,,,,)$fMemoizable(,,,,,,)$fMemoizable(,,,,,,,)$fMemoizable(,,,,,,,,)$fMemoizable(,,,,,,,,,)$fMemoizable(,,,,,,,,,,) FunctionCachefcNilfcConsFiniteToFinite fromFiniteicZero icNegative icPositiveBinaryTreeCachebtValuebtLeftbtRight theIntegers thePosInts integerLookup posIntLookup finiteLookup meanFinitefunctionLookup theFunctions_fib_isNot _countTrue$fMemoizable(->)$fMemoizableChar$fMemoizableInt$fMemoizableFinite$fMemoizableInteger$fMemoizable(,,,,,,,,,,,)