advent-0.1.0.0: Advent of Code common library
Copyright(c) Eric Mertens 2021
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Advent.Memo

Description

Re-exported MemoTrie operations and extended arity memoization.

Synopsis

Documentation

class HasTrie a #

Mapping from all elements of a to the results of some function

Minimal complete definition

trie, untrie, enumerate

Instances

Instances details
HasTrie Coord Source # 
Instance details

Defined in Advent.Coord

Associated Types

newtype Coord :->: a 
Instance details

Defined in Advent.Coord

newtype Coord :->: a = CT (Int :->: (Int :->: a))

Methods

trie :: (Coord -> b) -> Coord :->: b #

untrie :: (Coord :->: b) -> Coord -> b #

enumerate :: (Coord :->: b) -> [(Coord, b)] #

HasTrie SmallSet Source #

Instance derived from: HasTrie Word64

Instance details

Defined in Advent.SmallSet

Associated Types

newtype SmallSet :->: a 
Instance details

Defined in Advent.SmallSet

newtype SmallSet :->: a = T (Word64 :->: a)

Methods

trie :: (SmallSet -> b) -> SmallSet :->: b #

untrie :: (SmallSet :->: b) -> SmallSet -> b #

enumerate :: (SmallSet :->: b) -> [(SmallSet, b)] #

HasTrie Void 
Instance details

Defined in Data.MemoTrie

Associated Types

data Void :->: a 
Instance details

Defined in Data.MemoTrie

data Void :->: a = VoidTrie

Methods

trie :: (Void -> b) -> Void :->: b #

untrie :: (Void :->: b) -> Void -> b #

enumerate :: (Void :->: b) -> [(Void, b)] #

HasTrie Int16 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Int16 :->: a 
Instance details

Defined in Data.MemoTrie

newtype Int16 :->: a = Int16Trie (Word16 :->: a)

Methods

trie :: (Int16 -> b) -> Int16 :->: b #

untrie :: (Int16 :->: b) -> Int16 -> b #

enumerate :: (Int16 :->: b) -> [(Int16, b)] #

HasTrie Int32 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Int32 :->: a 
Instance details

Defined in Data.MemoTrie

newtype Int32 :->: a = Int32Trie (Word32 :->: a)

Methods

trie :: (Int32 -> b) -> Int32 :->: b #

untrie :: (Int32 :->: b) -> Int32 -> b #

enumerate :: (Int32 :->: b) -> [(Int32, b)] #

HasTrie Int64 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Int64 :->: a 
Instance details

Defined in Data.MemoTrie

newtype Int64 :->: a = Int64Trie (Word64 :->: a)

Methods

trie :: (Int64 -> b) -> Int64 :->: b #

untrie :: (Int64 :->: b) -> Int64 -> b #

enumerate :: (Int64 :->: b) -> [(Int64, b)] #

HasTrie Int8 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Int8 :->: a 
Instance details

Defined in Data.MemoTrie

newtype Int8 :->: a = Int8Trie (Word8 :->: a)

Methods

trie :: (Int8 -> b) -> Int8 :->: b #

untrie :: (Int8 :->: b) -> Int8 -> b #

enumerate :: (Int8 :->: b) -> [(Int8, b)] #

HasTrie Word16 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Word16 :->: a 
Instance details

Defined in Data.MemoTrie

newtype Word16 :->: a = Word16Trie ([Bool] :->: a)

Methods

trie :: (Word16 -> b) -> Word16 :->: b #

untrie :: (Word16 :->: b) -> Word16 -> b #

enumerate :: (Word16 :->: b) -> [(Word16, b)] #

HasTrie Word32 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Word32 :->: a 
Instance details

Defined in Data.MemoTrie

newtype Word32 :->: a = Word32Trie ([Bool] :->: a)

Methods

trie :: (Word32 -> b) -> Word32 :->: b #

untrie :: (Word32 :->: b) -> Word32 -> b #

enumerate :: (Word32 :->: b) -> [(Word32, b)] #

HasTrie Word64 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Word64 :->: a 
Instance details

Defined in Data.MemoTrie

newtype Word64 :->: a = Word64Trie ([Bool] :->: a)

Methods

trie :: (Word64 -> b) -> Word64 :->: b #

untrie :: (Word64 :->: b) -> Word64 -> b #

enumerate :: (Word64 :->: b) -> [(Word64, b)] #

HasTrie Word8 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Word8 :->: a 
Instance details

Defined in Data.MemoTrie

newtype Word8 :->: a = Word8Trie ([Bool] :->: a)

Methods

trie :: (Word8 -> b) -> Word8 :->: b #

untrie :: (Word8 :->: b) -> Word8 -> b #

enumerate :: (Word8 :->: b) -> [(Word8, b)] #

HasTrie Integer 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Integer :->: a 
Instance details

Defined in Data.MemoTrie

newtype Integer :->: a = IntegerTrie ((Bool, [Bool]) :->: a)

Methods

trie :: (Integer -> b) -> Integer :->: b #

untrie :: (Integer :->: b) -> Integer -> b #

enumerate :: (Integer :->: b) -> [(Integer, b)] #

HasTrie () 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype () :->: a 
Instance details

Defined in Data.MemoTrie

newtype () :->: a = UnitTrie a

Methods

trie :: (() -> b) -> () :->: b #

untrie :: (() :->: b) -> () -> b #

enumerate :: (() :->: b) -> [((), b)] #

HasTrie Bool 
Instance details

Defined in Data.MemoTrie

Associated Types

data Bool :->: x 
Instance details

Defined in Data.MemoTrie

data Bool :->: x = BoolTrie x x

Methods

trie :: (Bool -> b) -> Bool :->: b #

untrie :: (Bool :->: b) -> Bool -> b #

enumerate :: (Bool :->: b) -> [(Bool, b)] #

HasTrie Char 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Char :->: a 
Instance details

Defined in Data.MemoTrie

newtype Char :->: a = CharTrie (Int :->: a)

Methods

trie :: (Char -> b) -> Char :->: b #

untrie :: (Char :->: b) -> Char -> b #

enumerate :: (Char :->: b) -> [(Char, b)] #

HasTrie Int 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Int :->: a 
Instance details

Defined in Data.MemoTrie

newtype Int :->: a = IntTrie (Word :->: a)

Methods

trie :: (Int -> b) -> Int :->: b #

untrie :: (Int :->: b) -> Int -> b #

enumerate :: (Int :->: b) -> [(Int, b)] #

HasTrie Word 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype Word :->: a 
Instance details

Defined in Data.MemoTrie

newtype Word :->: a = WordTrie ([Bool] :->: a)

Methods

trie :: (Word -> b) -> Word :->: b #

untrie :: (Word :->: b) -> Word -> b #

enumerate :: (Word :->: b) -> [(Word, b)] #

HasTrie a => HasTrie (Maybe a) 
Instance details

Defined in Data.MemoTrie

Associated Types

data (Maybe a) :->: b 
Instance details

Defined in Data.MemoTrie

data (Maybe a) :->: b = MaybeTrie b (a :->: b)

Methods

trie :: (Maybe a -> b) -> Maybe a :->: b #

untrie :: (Maybe a :->: b) -> Maybe a -> b #

enumerate :: (Maybe a :->: b) -> [(Maybe a, b)] #

HasTrie x => HasTrie [x] 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype [x] :->: a 
Instance details

Defined in Data.MemoTrie

newtype [x] :->: a = ListTrie (Either () (x, [x]) :->: a)

Methods

trie :: ([x] -> b) -> [x] :->: b #

untrie :: ([x] :->: b) -> [x] -> b #

enumerate :: ([x] :->: b) -> [([x], b)] #

(HasTrie a, HasTrie b) => HasTrie (Either a b) 
Instance details

Defined in Data.MemoTrie

Associated Types

data (Either a b) :->: x 
Instance details

Defined in Data.MemoTrie

data (Either a b) :->: x = EitherTrie (a :->: x) (b :->: x)

Methods

trie :: (Either a b -> b0) -> Either a b :->: b0 #

untrie :: (Either a b :->: b0) -> Either a b -> b0 #

enumerate :: (Either a b :->: b0) -> [(Either a b, b0)] #

HasTrie (U1 x)

just like ()

Instance details

Defined in Data.MemoTrie

Associated Types

data (U1 x) :->: b 
Instance details

Defined in Data.MemoTrie

data (U1 x) :->: b = U1Trie b

Methods

trie :: (U1 x -> b) -> U1 x :->: b #

untrie :: (U1 x :->: b) -> U1 x -> b #

enumerate :: (U1 x :->: b) -> [(U1 x, b)] #

HasTrie (V1 x)

just like void

Instance details

Defined in Data.MemoTrie

Associated Types

data (V1 x) :->: b 
Instance details

Defined in Data.MemoTrie

data (V1 x) :->: b = V1Trie

Methods

trie :: (V1 x -> b) -> V1 x :->: b #

untrie :: (V1 x :->: b) -> V1 x -> b #

enumerate :: (V1 x :->: b) -> [(V1 x, b)] #

(HasTrie a, HasTrie b) => HasTrie (a, b) 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype (a, b) :->: x 
Instance details

Defined in Data.MemoTrie

newtype (a, b) :->: x = PairTrie (a :->: (b :->: x))

Methods

trie :: ((a, b) -> b0) -> (a, b) :->: b0 #

untrie :: ((a, b) :->: b0) -> (a, b) -> b0 #

enumerate :: ((a, b) :->: b0) -> [((a, b), b0)] #

(HasTrie a, HasTrie b, HasTrie c) => HasTrie (a, b, c) 
Instance details

Defined in Data.MemoTrie

Associated Types

newtype (a, b, c) :->: x 
Instance details

Defined in Data.MemoTrie

newtype (a, b, c) :->: x = TripleTrie (((a, b), c) :->: x)

Methods

trie :: ((a, b, c) -> b0) -> (a, b, c) :->: b0 #

untrie :: ((a, b, c) :->: b0) -> (a, b, c) -> b0 #

enumerate :: ((a, b, c) :->: b0) -> [((a, b, c), b0)] #

(HasTrie (f x), HasTrie (g x)) => HasTrie ((f :*: g) x)

wraps (f x, g x)

Instance details

Defined in Data.MemoTrie

Associated Types

newtype ((f :*: g) x) :->: b 
Instance details

Defined in Data.MemoTrie

newtype ((f :*: g) x) :->: b = PairTrie1 ((f x, g x) :->: b)

Methods

trie :: ((f :*: g) x -> b) -> (f :*: g) x :->: b #

untrie :: ((f :*: g) x :->: b) -> (f :*: g) x -> b #

enumerate :: ((f :*: g) x :->: b) -> [((f :*: g) x, b)] #

(HasTrie (f x), HasTrie (g x)) => HasTrie ((f :+: g) x)

wraps Either (f x) (g x)

Instance details

Defined in Data.MemoTrie

Associated Types

newtype ((f :+: g) x) :->: b 
Instance details

Defined in Data.MemoTrie

newtype ((f :+: g) x) :->: b = EitherTrie1 (Either (f x) (g x) :->: b)

Methods

trie :: ((f :+: g) x -> b) -> (f :+: g) x :->: b #

untrie :: ((f :+: g) x :->: b) -> (f :+: g) x -> b #

enumerate :: ((f :+: g) x :->: b) -> [((f :+: g) x, b)] #

HasTrie a => HasTrie (K1 i a x)

wraps a

Instance details

Defined in Data.MemoTrie

Associated Types

data (K1 i a x) :->: b 
Instance details

Defined in Data.MemoTrie

data (K1 i a x) :->: b = K1Trie (a :->: b)

Methods

trie :: (K1 i a x -> b) -> K1 i a x :->: b #

untrie :: (K1 i a x :->: b) -> K1 i a x -> b #

enumerate :: (K1 i a x :->: b) -> [(K1 i a x, b)] #

HasTrie (f x) => HasTrie (M1 i t f x)

wraps f x

Instance details

Defined in Data.MemoTrie

Associated Types

data (M1 i t f x) :->: b 
Instance details

Defined in Data.MemoTrie

data (M1 i t f x) :->: b = M1Trie (f x :->: b)

Methods

trie :: (M1 i t f x -> b) -> M1 i t f x :->: b #

untrie :: (M1 i t f x :->: b) -> M1 i t f x -> b #

enumerate :: (M1 i t f x :->: b) -> [(M1 i t f x, b)] #

memo :: HasTrie t => (t -> a) -> t -> a #

Trie-based function memoizer

memo2 :: (HasTrie s, HasTrie t) => (s -> t -> a) -> s -> t -> a #

Memoize a binary function, on its first argument and then on its second. Take care to exploit any partial evaluation.

memo3 :: (HasTrie r, HasTrie s, HasTrie t) => (r -> s -> t -> a) -> r -> s -> t -> a #

Memoize a ternary function on successive arguments. Take care to exploit any partial evaluation.

memo4 :: (HasTrie a, HasTrie b, HasTrie c, HasTrie d) => (a -> b -> c -> d -> e) -> a -> b -> c -> d -> e Source #

Memoize a quaternary function on successive arguments. Take care to exploit any partial evaluation.

memo5 :: (HasTrie a, HasTrie b, HasTrie c, HasTrie d, HasTrie e) => (a -> b -> c -> d -> e -> f) -> a -> b -> c -> d -> e -> f Source #

Memoize a quaternary function on successive arguments. Take care to exploit any partial evaluation.

memo6 :: (HasTrie a, HasTrie b, HasTrie c, HasTrie d, HasTrie e, HasTrie f) => (a -> b -> c -> d -> e -> f -> g) -> a -> b -> c -> d -> e -> f -> g Source #

Memoize a quaternary function on successive arguments. Take care to exploit any partial evaluation.