## Memo Functions, Polytypically! (2000)

Venue: | Proceedings of the 2nd Workshop on Generic Programming, Ponte de |

Citations: | 13 - 5 self |

### BibTeX

@INPROCEEDINGS{Hinze00memofunctions,,

author = {Ralf Hinze},

title = {Memo Functions, Polytypically!},

booktitle = {Proceedings of the 2nd Workshop on Generic Programming, Ponte de},

year = {2000},

pages = {17--32}

}

### Years of Citing Articles

### OpenURL

### Abstract

. This paper presents a polytypic implementation of memo functions that are based on digital search trees. A memo function can be seen as the composition of a tabulation function that creates a memo table and a look-up function that queries the table. We show that tabulation can be derived from look-up by inverse function construction. The type of memo tables is dened by induction on the structure of argument types and is parametric with respect to the result type of memo functions. A memo table for a xed argument type is then a functor and look-up and tabulation are natural isomorphisms. We provide simple polytypic proofs of these properties. 1 Introduction A memo function [11] is like an ordinary function except that it caches previously computed values. If it is applied a second time to a particular argument, it immediately returns the cached result, rather than recomputing it. For storing arguments and results a memo function internally employs an index structure, the ...

### Citations

107 | Polytypic values possess polykinded types
- Hinze
- 2000
(Show Context)
Citation Context ...gant and ecient implementation of memo functions. This paper is a direct descendant of my earlier work on generalized tries [5], which in turn relies heavily on the framework of polytypic programming =-=[7, 6, 8-=-]. The central insight is that a trie can be considered as a type-indexed datatype 2 R. Hinze that is dened by induction on the structure of types. The look-up function then enjoys a straightforward p... |

94 | A new approach to generic functional programming
- Hinze
- 2000
(Show Context)
Citation Context ...gant and ecient implementation of memo functions. This paper is a direct descendant of my earlier work on generalized tries [5], which in turn relies heavily on the framework of polytypic programming =-=[7, 6, 8-=-]. The central insight is that a trie can be considered as a type-indexed datatype 2 R. Hinze that is dened by induction on the structure of types. The look-up function then enjoys a straightforward p... |

85 |
Polymorphic Type Inference
- Leivant
- 1983
(Show Context)
Citation Context ...ametric type, applyList is a `higher-order' look-up function that takes a look-up function for the base type a and yields a lookup function for List a. Note that applyList has a rank-2 type signature =-=[10]-=-, which is not legal Haskell. However, recent versions of the Glasgow Haskell Compiler GHC [16] and the Haskell interpreter Hugs [9] support rank-2 types. ut 3.3 Tabulation Tabulation is the inverse o... |

84 | Generic programming – an introduction
- Backhouse, Jansson, et al.
- 1999
(Show Context)
Citation Context ...e its denition by inverse function construction. For the derivation we use a slight reformulation of apply that allows for more structured calculations (`O' is the junk combinator, see, for instance [2]). applyhki :: 8v :Tablehki v ! (k ! v) applyh1i t = ():t applyhk 1 + k 2 i t = applyhk 1 i (outl t) O apply hk 2 i (outr t) applyhk 1 k 2 i t = uncurry (apply hk 2 i applyhk 1 i t) We specify ta... |

79 | Nested datatypes
- BIRD, MEERTENS
- 1998
(Show Context)
Citation Context ...) Note that the two occurrences of TablehTreei on the right-hand side are nested. Indeed, the Haskell type TTree data TTree v = NTree v (TTree (TTree v)) is an example for a so-called nested datatype =-=[3-=-]. An element of type TTree v is like an innite list except that the n-th entry has type TTree n v (a similar type appears in the seminal paper on nested datatypes [3]). ut Example 7. Finally, let us ... |

47 | Hash-consing garbage collection
- Appel, Goncalves
- 1993
(Show Context)
Citation Context ...rohibitive. Hash tables are no viable alternative as hashing compound values is dicult. Furthermore, in case of collisions values must be checked for equality (though a hash-consing garbage collector =-=[1]-=- may alleviate this problem). For memo functions with compound argument types digital search trees, also known as tries, are the data structure of choice. Looking up a value in a trie takes time propo... |

36 |
The Semanticc Elegance of Applicative Languages
- Turner
- 1981
(Show Context)
Citation Context ...ple 7). Note that this instance, the use of innite lists for memoizing functions on the natural numbers, already appears in the paper on `The Semantic Elegance of Applicative Languages' by D. Turner [=-=17-=-]. ut Example 5. The following alternative denition of the natural numbers is based on the binary number system (using the digits 1 and 2). data Bin = End j One Bin j Two Bin The associated memo table... |

31 | Generalizing generalized tries
- Hinze
(Show Context)
Citation Context ...of memoized values. In combination with lazy evaluation tries provide an elegant and ecient implementation of memo functions. This paper is a direct descendant of my earlier work on generalized tries =-=[5-=-], which in turn relies heavily on the framework of polytypic programming [7, 6, 8]. The central insight is that a trie can be considered as a type-indexed datatype 2 R. Hinze that is dened by inducti... |

25 |
Memo functions and machine learning. Nature
- Michie
(Show Context)
Citation Context ...ons. A memo table for asxed argument type is then a functor and look-up and tabulation are natural isomorphisms. We provide simple polytypic proofs of these properties. 1 Introduction A memo function =-=[11]-=- is like an ordinary function except that it caches previously computed values. If it is applied a second time to a particular argument, it immediately returns the cached result, rather than recomputi... |

13 | Polytypic programming with ease
- HINZE
- 1999
(Show Context)
Citation Context ...gant and ecient implementation of memo functions. This paper is a direct descendant of my earlier work on generalized tries [5], which in turn relies heavily on the framework of polytypic programming =-=[7, 6, 8-=-]. The central insight is that a trie can be considered as a type-indexed datatype 2 R. Hinze that is dened by induction on the structure of types. The look-up function then enjoys a straightforward p... |

12 |
Algorithms: a Functional Programming Approach
- Rabhi, Lapalme
- 1999
(Show Context)
Citation Context ...es (which are small) rather than by sequences of matrix dimensions (which may be be very large). The resulting code corresponds closely to the standard dynamic programming solution, see, for instance =-=[15-=-]. ut 4 Properties For asxed k , the type constructor Tablehki satises the properties of a functor (it is an endo functor of Cpo ? ). Its functorial action on arrows is given by tablehki :: 8v w :(v !... |

11 |
A generalization of the trie data structure
- Connelly, Morris
- 1995
(Show Context)
Citation Context ...e. We also require full laziness so that tabulatehki ' is evaluated only once even if it is queried several times. Haskell meets both requirements. 3.1 Memo tables Tries, or rather, generalized tries [4] enjoy asrm mathematical foundation: they are based on the laws of exponentials. 1 ! v = v (k 1 + k 2 ) ! v = (k 1 ! v) (k 2 ! v) (k 1 k 2 ) ! v = k 1 ! (k 2 ! v) Note that the last equation... |

10 |
Polymorphic type schemes and recursive de
- Mycroft
- 1984
(Show Context)
Citation Context ... 8v :TTree v ! (Tree ! v) applyTree (NTree tl tf ) Leaf = tl applyTree (NTree tl tf ) (Fork l r) = applyTree (applyTree tf l ) r Since TTree is a nested type, applyTree requires polymorphic recursion =-=[12]-=-. ut Example 11. As thesnal example, consider the look-up function for lists. applyList :: 8ta a:(8v :ta v ! (a ! v)) ! (8w :TList ta w ! (List a ! w)) applyList applya (NList tn tc) Nil = tn applyLis... |

5 |
Available from http://www.haskell.org/hugs
- Jones, Peterson
- 1999
(Show Context)
Citation Context ...nction for List a. Note that applyList has a rank-2 type signature [10], which is not legal Haskell. However, recent versions of the Glasgow Haskell Compiler GHC [16] and the Haskell interpreter Hugs =-=[9-=-] support rank-2 types. ut 3.3 Tabulation Tabulation is the inverse of look-up and, in fact, we can derive its denition by inverse function construction. For the derivation we use a slight reformulati... |

4 |
Equational Logic as a Programming Language. Foundations of Computing
- O'Donnell
- 1985
(Show Context)
Citation Context ...the modied version of cost is omitted for reasons of space). memo-cost :: List Nat ! Nat memo-cost = (applyList applyNat ) ((tabulateList tabulateNat) cost) An ad-hoc variant of this code appears in [=-=13-=-]. ut Example 16. The function memo-cost dened in the previous example maintains a global memo table. This comes at a considerable cost: recall that functions on the natural numbers are memoized using... |