mirror of
https://github.com/github/semantic.git
synced 2024-12-25 16:02:43 +03:00
Add a generalization of memoize to Enums.
This commit is contained in:
parent
8096dcd588
commit
e31b8e3f57
@ -84,6 +84,9 @@ diffAt' diffTerms cost as bs recur (i, j)
|
|||||||
memoize :: (Int -> a) -> (Int -> a)
|
memoize :: (Int -> a) -> (Int -> a)
|
||||||
memoize f = (fmap f [0 ..] !!)
|
memoize f = (fmap f [0 ..] !!)
|
||||||
|
|
||||||
|
memoizeEnum :: Enum a => (a -> b) -> a -> b
|
||||||
|
memoizeEnum f = (fmap f [toEnum 0 ..] !!) . fromEnum
|
||||||
|
|
||||||
memoize2 :: ((Int, Int) -> a) -> ((Int, Int) -> a)
|
memoize2 :: ((Int, Int) -> a) -> ((Int, Int) -> a)
|
||||||
memoize2 f = fromJust . (`lookup` memo)
|
memoize2 f = fromJust . (`lookup` memo)
|
||||||
where memo = zipWith (\ i j -> ((i, j), f (i, j))) [0 ..] [0 ..]
|
where memo = zipWith (\ i j -> ((i, j), f (i, j))) [0 ..] [0 ..]
|
||||||
|
Loading…
Reference in New Issue
Block a user