Data.Function.Memoize
- Package
- purescript-open-memoize
- Repository
- purescript-open-community/purescript-open-memoize
This module defines functions for memoizing functions, i.e. creating functions which remember their results.
This module works by turning a function into a lazily-evaluated data structure depending on its domain type.
#Tabulate Source
class Tabulate a whereThe Tabulate class identifies those types which can be used as the domain of
a memoized function, i.e. those for which the results can be tabulated.
Members
Instances
Tabulate UnitTabulate NoArgumentsTabulate BooleanTabulate CharTabulate String(Tabulate a) => Tabulate (Constructor name a)(Tabulate a) => Tabulate (Argument a)(Tabulate a) => Tabulate (Maybe a)(Tabulate a, Tabulate b) => Tabulate (Either a b)(Tabulate a, Tabulate b) => Tabulate (Sum a b)(Tabulate a, Tabulate b) => Tabulate (Tuple a b)(Tabulate a, Tabulate b) => Tabulate (Product a b)(Tabulate a) => Tabulate (List a)(Tabulate a) => Tabulate (Array a)Tabulate Int
#genericTabulate Source
genericTabulate :: forall a r rep. Generic a rep => Tabulate rep => (a -> r) -> a -> Lazy rA default implementation of Tabulate for Generic types.
Given a data type made up of data types with Tabulate instances:
data MyDataType
= A Int
| B String
First, derive an instance of Data.Generics.Rep.Generic:
derive instance genericMyDataType :: Generic MyDataType _
Now, Tabulate can be defined in terms of genericTabulate:
instance tabulateMyDataType :: Tabulate MyDataType where
tabulate = genericTabulate
Note: this function should not be used to derive instances for recursive data types, and attempting to do so will lead to stack overflow errors at runtime.
- Modules
- Data.
Function. Memoize