on 3524599 help sign in
8 files changed+95−353
since splitsnapshots
unifiedsplit
.gitignore−15 Makefile+8 MemoTrie.cabal+9−33 README.md−9 examples/Generic.hs−25 src/Data/MemoTrie.hs+57−264 stack.yaml−7 wikipage.tw+21
.gitignoredeleted−15
@@ -1,15 +0,0 @@
1−*~
2−Junk*
3−Old*
4−dist
5−Stuff
6−TAGS
7−tags
8−tarballs
9−
10−# Mac OS generates
11−.DS_Store
12−
13−# Where do these files come from? They're not readable.
14−# For instance, .#Help.page
15−.#*
Makefile+8
@@ -1 +1,9 @@
1+# For special configuration, especially for docs. Otherwise see README.
2+
3+server = code.haskell.org
4+server-dir = /srv/code
5+server-url-dir =
6+
7+# extra-configure-args += --enable-library-profiling --enable-executable-profiling
8+
19include ../my-cabal-make.inc
MemoTrie.cabal+9−33
@@ -1,54 +1,30 @@
11Name: MemoTrie
2−Version: 0.6.10
3−Cabal-Version: >= 1.10
2+Version: 0.4.13
3+Cabal-Version: >= 1.2
44Synopsis: Trie-based memo functions
55Category: Data
66Description:
77 MemoTrie provides a basis for memoized functions over some domains,
88 using tries. It's based on ideas from Ralf Hinze and code from
9− Spencer Janssen. Generic support thanks to Sam Boosalis.
9+ Spencer Janssen.
1010 .
1111 Project wiki page: <http://haskell.org/haskellwiki/MemoTrie>
1212 .
13− &#199; 2008-2019 by Conal Elliott; BSD3 license.
14−Homepage: https://github.com/conal/MemoTrie
13+ &#169; 2008-2012 by Conal Elliott; BSD3 license.
1514Author: Conal Elliott
1615Maintainer: conal@conal.net
17−Copyright: (c) 2008-2019 by Conal Elliott
16+Homepage: http://haskell.org/haskellwiki/MemoTrie
17+Package-Url: http://code.haskell.org/MemoTrie
18+Copyright: (c) 2008-2012 by Conal Elliott
1819License: BSD3
1920License-File: COPYING
2021Stability: experimental
2122build-type: Simple
2223
23−source-repository head
24− type: git
25− location: git://github.com/conal/MemoTrie.git
26−
27−Flag examples
28− Description: "examples"
29− Default: False
30− Manual: True
31−
3224Library
3325 hs-Source-Dirs: src
34−
35− if impl(ghc >= 7.10.0)
36− Build-Depends: base >=4.8.0.0 && <5, newtype-generics >= 0.5.3
37− else
38− Build-Depends: base <4.8.0.0, void, newtype-generics >= 0.5.3
39−
26+ Extensions:
27+ Build-Depends: base < 5, void
4028 Exposed-Modules:
4129 Data.MemoTrie
42− Other-Modules:
43−
44− default-language: Haskell2010
45−
46−executable generic
47− if !flag(examples)
48− buildable: False
49− main-is: Generic.hs
5030 ghc-options: -Wall
51− hs-source-dirs: examples
52− default-language: Haskell2010
53− build-depends: base, MemoTrie
54−
README.mddeleted−9
@@ -1,9 +0,0 @@
1−*MemoTrie* is functional library for creating efficient memo functions, using [tries](http://en.wikipedia.org/wiki/Trie "http://en.wikipedia.org/wiki/Trie").
2−It's based on some code from Spencer Janssen (originally put on hpaste.org, now expired), which I assume was based on Ralf Hinze's paper [*Memo functions, polytypically!*](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.43.3272 "http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.43.3272").
3−
4−Install with `cabal install Memotrie`.
5−
6−See also
7−
8−* Library documentation [on Hackage](http://hackage.haskell.org/package/MemoTrie).
9−* Related [blog posts](http://conal.net/blog/tag/trie/ "http://conal.net/blog/tag/trie/").
examples/Generic.hsdeleted−25
@@ -1,25 +0,0 @@
1−{-# LANGUAGE DeriveGeneric, TypeOperators, TypeFamilies #-}
2−import Data.MemoTrie
3−import GHC.Generics (Generic)
4−
5−data Color = RGB Int Int Int
6− | NamedColor String
7− deriving (Generic)
8−
9−instance HasTrie Color where
10− newtype (Color :->: b) = ColorTrie { unColorTrie :: Reg Color :->: b }
11− trie = trieGeneric ColorTrie
12− untrie = untrieGeneric unColorTrie
13− enumerate = enumerateGeneric unColorTrie
14−
15−runColor (RGB r g b) = r + g + b
16−runColor (NamedColor s) = length [1..10e7]
17−
18−runColorMemoized = memo runColor
19−
20−main =
21− do putStrLn "first call (should take a few seconds): "
22− print$ runColorMemoized (NamedColor "")
23− putStrLn "cached call (should be instantaneous): "
24− print$ runColorMemoized (NamedColor "")
25−
src/Data/MemoTrie.hs+57−264
@@ -1,15 +1,12 @@
11{-# LANGUAGE GADTs, TypeFamilies, TypeOperators, ScopedTypeVariables, CPP #-}
2−{-# LANGUAGE StandaloneDeriving, FlexibleInstances #-}
3−{-# LANGUAGE DefaultSignatures, FlexibleContexts, LambdaCase #-}
42{-# OPTIONS_GHC -Wall -fenable-rewrite-rules #-}
5−
63-- ScopedTypeVariables works around a 6.10 bug. The forall keyword is
74-- supposed to be recognized in a RULES pragma.
85
96----------------------------------------------------------------------
107-- |
118-- Module : Data.MemoTrie
12−-- Copyright : (c) Conal Elliott 2008-2016
9+-- Copyright : (c) Conal Elliott 2008-2012
1310-- License : BSD3
1411--
1512-- Maintainer : conal@conal.net
@@ -17,69 +14,33 @@
1714--
1815-- Trie-based memoizer
1916--
20−-- Adapted from sjanssen's paste: <http://hpaste.org/3839 \"a lazy trie\">,
17+-- Adapted from sjanssen's paste: \"a lazy trie\" <http://hpaste.org/3839>,
2118-- which I think is based on Ralf Hinze's paper "Memo Functions,
2219-- Polytypically!".
23−--
24−-- You can automatically derive generic instances. for example:
25−--
26−-- @
27−-- {-# LANGUAGE <https://ocharles.org.uk/blog/posts/2014-12-16-derive-generic.html DeriveGeneric>, TypeOperators, TypeFamilies #-}
28−-- import Data.MemoTrie
29−-- import GHC.Generics (Generic)
30−--
31−-- data Color = RGB Int Int Int
32−-- | NamedColor String
33−-- deriving ('Generic')
34−--
35−-- instance HasTrie Color where
36−-- newtype (Color :->: b) = ColorTrie { unColorTrie :: 'Reg' Color :->: b }
37−-- trie = 'trieGeneric' ColorTrie
38−-- untrie = 'untrieGeneric' unColorTrie
39−-- enumerate = 'enumerateGeneric' unColorTrie
40−-- @
41−--
42−-- see @examples/Generic.hs@, which can be run with:
43−--
44−-- @
45−-- cabal configure -fexamples && cabal run generic
46−-- @
47−--
48−--
4920----------------------------------------------------------------------
5021
5122module Data.MemoTrie
52− ( HasTrie(..), (:->:)(..)
23+ ( HasTrie, (:->:)(..), trie, untrie, enumerate
5324 , domain, idTrie, (@.@)
5425 -- , trie2, trie3, untrie2, untrie3
5526 , memo, memo2, memo3, mup
5627 , inTrie, inTrie2, inTrie3
5728 -- , untrieBits
58− , trieGeneric, untrieGeneric, enumerateGeneric, Reg
59− , memoFix
6029 ) where
6130
6231-- Export the parts of HasTrie separately in order to get the associated data
6332-- type constructors, so I can define instances of other classes on them.
6433
65−import Data.Function (fix)
6634import Data.Bits
6735import Data.Word
6836import Data.Int
69−#if !MIN_VERSION_base(4,8,0)
7037import Control.Applicative
71−#endif
7238import Control.Arrow (first,(&&&))
73−#if !MIN_VERSION_base(4,8,0)
7439import Data.Monoid
75−#endif
7640import Data.Function (on)
77−import GHC.Generics
7841
79−import Control.Newtype.Generics
42+import Data.Void
8043
81−import Data.Void (Void)
82−
8344-- import Prelude hiding (id,(.))
8445-- import Control.Category
8546-- import Control.Arrow
@@ -136,13 +97,9 @@ untrie3 tt = untrie2 . untrie tt
13697-}
13798
13899
139−-- {-# RULES "trie/untrie" forall t. trie (untrie t) = t #-}
140−
141−-- warning: [-Winline-rule-shadowing] …
142−-- Rule "trie/untrie" may never fire
143−-- because rule "Class op untrie" for ‘untrie’ might fire first
144−-- Probable fix: add phase [n] or [~n] to the competing rule
145−
100+{-# RULES
101+"trie/untrie" forall t. trie (untrie t) = t
102+ #-}
146103
147104-- Don't include the dual rule:
148105-- "untrie/trie" forall f. untrie (trie f) = f
@@ -170,42 +127,6 @@ mup mem f = memo (mem . f)
170127memo2 = mup memo
171128memo3 = mup memo2
172129
173−-- | Memoizing recursion. Use like `fix`.
174−memoFix :: HasTrie a => ((a -> b) -> (a -> b)) -> (a -> b)
175−memoFix h = fix (memo . h)
176−
177−#if 0
178−-- Equivalently,
179−
180−memoFix h = fix (\ f' -> memo (h f'))
181−
182−memoFix h = f'
183− where f' = memo (h f')
184−
185−memoFix h = f'
186− where
187− f' = memo f
188− f = h f'
189−#endif
190−
191−#if 0
192−-- Example
193−
194−fibF :: (Integer -> Integer) -> (Integer -> Integer)
195−fibF _ 0 = 1
196−fibF _ 1 = 1
197−fibF f n = f (n-1) + f (n-2)
198−
199−fib :: Integer -> Integer
200−fib = fix fibF
201−
202−fib' :: Integer -> Integer
203−fib' = memoFix fibF
204−
205−-- Try fib 30 vs fib' 30
206−#endif
207−
208−
209130-- | Apply a unary function inside of a trie
210131inTrie :: (HasTrie a, HasTrie c) =>
211132 ((a -> b) -> (c -> d))
@@ -228,28 +149,17 @@ inTrie3 = untrie ~> inTrie2
228149---- Instances
229150
230151instance HasTrie Void where
231− -- As suggested by Audun Skaugen
232− data Void :->: a = VoidTrie
152+ -- As suggested by Audun
153+ data Void :->: a = VoidTrie
233154 trie _ = VoidTrie
234− untrie VoidTrie = \ _ -> error "untrie VoidTrie"
235− -- \case -- needs EmptyCase
155+ untrie VoidTrie = absurd
236156 enumerate VoidTrie = []
237157
238−instance Newtype (Void :->: a) where
239− type O (Void :->: a) = ()
240− pack () = VoidTrie
241− unpack VoidTrie = ()
242−
243158instance HasTrie () where
244− newtype () :->: a = UnitTrie a
245− trie f = UnitTrie (f ())
246− untrie (UnitTrie a) = \ () -> a
247− enumerate (UnitTrie a) = [((),a)]
248−
249−instance Newtype (() :->: a) where
250− type O (() :->: a) = a
251− pack a = UnitTrie a
252− unpack (UnitTrie a) = a
159+ newtype () :->: a = UnitTrie a
160+ trie f = UnitTrie (f ())
161+ untrie (UnitTrie a) = \ () -> a
162+ enumerate (UnitTrie a) = [((),a)]
253163
254164-- Proofs of inverse properties:
255165
@@ -281,15 +191,10 @@ memoizing hyper-strict functions.
281191
282192
283193instance HasTrie Bool where
284− data Bool :->: x = BoolTrie x x
285− trie f = BoolTrie (f False) (f True)
286− untrie (BoolTrie f t) = if' f t
287− enumerate (BoolTrie f t) = [(False,f),(True,t)]
288−
289−instance Newtype (Bool :->: a) where
290− type O (Bool :->: a) = (a,a)
291− pack (a,a') = BoolTrie a a'
292− unpack (BoolTrie a a') = (a,a')
194+ data Bool :->: x = BoolTrie x x
195+ trie f = BoolTrie (f False) (f True)
196+ untrie (BoolTrie f t) = if' f t
197+ enumerate (BoolTrie f t) = [(False,f),(True,t)]
293198
294199-- | Conditional with boolean last.
295200-- Spec: @if' (f False) (f True) == f@
@@ -315,27 +220,12 @@ if' _ e True = e
315220 BoolTrie f t
316221-}
317222
318−instance HasTrie a => HasTrie (Maybe a) where
319− data (:->:) (Maybe a) b = MaybeTrie b (a :->: b)
320− trie f = MaybeTrie (f Nothing) (trie (f . Just))
321− untrie (MaybeTrie nothing_val a_trie) = maybe nothing_val (untrie a_trie)
322− enumerate (MaybeTrie nothing_val a_trie) = (Nothing, nothing_val) : enum' Just a_trie
323−
324−instance Newtype (Maybe a :->: x) where
325− type O (Maybe a :->: x) = (x, a :->: x)
326− pack (a,f) = MaybeTrie a f
327− unpack (MaybeTrie a f) = (a,f)
328223
329224instance (HasTrie a, HasTrie b) => HasTrie (Either a b) where
330− data (Either a b) :->: x = EitherTrie (a :->: x) (b :->: x)
331− trie f = EitherTrie (trie (f . Left)) (trie (f . Right))
332− untrie (EitherTrie s t) = either (untrie s) (untrie t)
333− enumerate (EitherTrie s t) = enum' Left s `weave` enum' Right t
334−
335−instance Newtype (Either a b :->: x) where
336− type O (Either a b :->: x) = (a :->: x, b :->: x)
337− pack (f,g) = EitherTrie f g
338− unpack (EitherTrie f g) = (f,g)
225+ data (Either a b) :->: x = EitherTrie (a :->: x) (b :->: x)
226+ trie f = EitherTrie (trie (f . Left)) (trie (f . Right))
227+ untrie (EitherTrie s t) = either (untrie s) (untrie t)
228+ enumerate (EitherTrie s t) = enum' Left s `weave` enum' Right t
339229
340230enum' :: (HasTrie a) => (a -> a') -> (a :->: b) -> [(a', b)]
341231enum' f = (fmap.first) f . enumerate
@@ -370,16 +260,11 @@ as `weave` [] = as
370260
371261
372262instance (HasTrie a, HasTrie b) => HasTrie (a,b) where
373− newtype (a,b) :->: x = PairTrie (a :->: (b :->: x))
374− trie f = PairTrie (trie (trie . curry f))
375− untrie (PairTrie t) = uncurry (untrie . untrie t)
376− enumerate (PairTrie tt) =
377− [ ((a,b),x) | (a,t) <- enumerate tt , (b,x) <- enumerate t ]
378−
379−instance Newtype ((a,b) :->: x) where
380− type O ((a,b) :->: x) = a :->: b :->: x
381− pack abx = PairTrie abx
382− unpack (PairTrie abx) = abx
263+ newtype (a,b) :->: x = PairTrie (a :->: (b :->: x))
264+ trie f = PairTrie (trie (trie . curry f))
265+ untrie (PairTrie t) = uncurry (untrie . untrie t)
266+ enumerate (PairTrie tt) =
267+ [ ((a,b),x) | (a,t) <- enumerate tt , (b,x) <- enumerate t ]
383268
384269{-
385270 untrie (trie f)
@@ -408,10 +293,10 @@ instance Newtype ((a,b) :->: x) where
408293-}
409294
410295instance (HasTrie a, HasTrie b, HasTrie c) => HasTrie (a,b,c) where
411− newtype (a,b,c) :->: x = TripleTrie (((a,b),c) :->: x)
412− trie f = TripleTrie (trie (f . trip))
413− untrie (TripleTrie t) = untrie t . detrip
414− enumerate (TripleTrie t) = enum' trip t
296+ newtype (a,b,c) :->: x = TripleTrie (((a,b),c) :->: x)
297+ trie f = TripleTrie (trie (f . trip))
298+ untrie (TripleTrie t) = untrie t . detrip
299+ enumerate (TripleTrie t) = enum' trip t
415300
416301trip :: ((a,b),c) -> (a,b,c)
417302trip ((a,b),c) = (a,b,c)
@@ -421,10 +306,10 @@ detrip (a,b,c) = ((a,b),c)
421306
422307
423308instance HasTrie x => HasTrie [x] where
424− newtype [x] :->: a = ListTrie (Either () (x,[x]) :->: a)
425− trie f = ListTrie (trie (f . list))
426− untrie (ListTrie t) = untrie t . delist
427− enumerate (ListTrie t) = enum' list t
309+ newtype [x] :->: a = ListTrie (Either () (x,[x]) :->: a)
310+ trie f = ListTrie (trie (f . list))
311+ untrie (ListTrie t) = untrie t . delist
312+ enumerate (ListTrie t) = enum' list t
428313
429314list :: Either () (x,[x]) -> [x]
430315list = either (const []) (uncurry (:))
@@ -435,10 +320,10 @@ delist (x:xs) = Right (x,xs)
435320
436321#define WordInstance(Type,TrieType)\
437322instance HasTrie Type where \
438− newtype Type :->: a = TrieType ([Bool] :->: a);\
439− trie f = TrieType (trie (f . unbits));\
440− untrie (TrieType t) = untrie t . bits;\
441− enumerate (TrieType t) = enum' unbits t
323+ newtype Type :->: a = TrieType ([Bool] :->: a);\
324+ trie f = TrieType (trie (f . unbits));\
325+ untrie (TrieType t) = untrie t . bits;\
326+ enumerate (TrieType t) = enum' unbits t
442327
443328WordInstance(Word,WordTrie)
444329WordInstance(Word8,Word8Trie)
@@ -447,10 +332,10 @@ WordInstance(Word32,Word32Trie)
447332WordInstance(Word64,Word64Trie)
448333
449334-- instance HasTrie Word where
450−-- newtype Word :->: a = WordTrie ([Bool] :->: a)
451−-- trie f = WordTrie (trie (f . unbits))
452−-- untrie (WordTrie t) = untrie t . bits
453−-- enumerate (WordTrie t) = enum' unbits t
335+-- newtype Word :->: a = WordTrie ([Bool] :->: a)
336+-- trie f = WordTrie (trie (f . unbits))
337+-- untrie (WordTrie t) = untrie t . bits
338+-- enumerate (WordTrie t) = enum' unbits t
454339
455340
456341-- | Extract bits in little-endian order
@@ -469,10 +354,10 @@ unbits [] = 0
469354unbits (x:xs) = unbit x .|. shiftL (unbits xs) 1
470355
471356instance HasTrie Char where
472− newtype Char :->: a = CharTrie (Int :->: a)
473− untrie (CharTrie t) n = untrie t (fromEnum n)
474− trie f = CharTrie (trie (f . toEnum))
475− enumerate (CharTrie t) = enum' toEnum t
357+ newtype Char :->: a = CharTrie (Int :->: a)
358+ untrie (CharTrie t) n = untrie t (fromEnum n)
359+ trie f = CharTrie (trie (f . toEnum))
360+ enumerate (CharTrie t) = enum' toEnum t
476361
477362-- Although Int is a Bits instance, we can't use bits directly for
478363-- memoizing, because the "bits" function gives an infinite result, since
@@ -481,10 +366,10 @@ instance HasTrie Char where
481366
482367#define IntInstance(IntType,WordType,TrieType) \
483368instance HasTrie IntType where \
484− newtype IntType :->: a = TrieType (WordType :->: a); \
485− untrie (TrieType t) n = untrie t (fromIntegral n); \
486− trie f = TrieType (trie (f . fromIntegral)); \
487− enumerate (TrieType t) = enum' fromIntegral t
369+ newtype IntType :->: a = TrieType (WordType :->: a); \
370+ untrie (TrieType t) n = untrie t (fromIntegral n); \
371+ trie f = TrieType (trie (f . fromIntegral)); \
372+ enumerate (TrieType t) = enum' fromIntegral t
488373
489374IntInstance(Int,Word,IntTrie)
490375IntInstance(Int8,Word8,Int8Trie)
@@ -496,10 +381,10 @@ IntInstance(Int64,Word64,Int64Trie)
496381-- extract the sign bit.
497382
498383instance HasTrie Integer where
499− newtype Integer :->: a = IntegerTrie ((Bool,[Bool]) :->: a)
500− trie f = IntegerTrie (trie (f . unbitsZ))
501− untrie (IntegerTrie t) = untrie t . bitsZ
502− enumerate (IntegerTrie t) = enum' unbitsZ t
384+ newtype Integer :->: a = IntegerTrie ((Bool,[Bool]) :->: a)
385+ trie f = IntegerTrie (trie (f . unbitsZ))
386+ untrie (IntegerTrie t) = untrie t . bitsZ
387+ enumerate (IntegerTrie t) = enum' unbitsZ t
503388
504389
505390unbitsZ :: (Num n, Bits n) => (Bool,[Bool]) -> n
@@ -587,12 +472,7 @@ instance HasTrie a => Monad ((:->:) a) where
587472
588473instance (HasTrie a, Monoid b) => Monoid (a :->: b) where
589474 mempty = trie mempty
590−#if !MIN_VERSION_base(4,11,0)
591475 mappend = inTrie2 mappend
592−#else
593−instance (HasTrie a, Semigroup b) => Semigroup (a :->: b) where
594− (<>) = inTrie2 (<>)
595−#endif
596476
597477instance HasTrie a => Functor ((:->:) a) where
598478 fmap f = inTrie (fmap f)
@@ -616,6 +496,7 @@ infixr 9 @.@
616496(@.@) = inTrie2 (.)
617497
618498
499+
619500-- instance Category (:->:) where
620501-- id = idTrie
621502-- (.) = (.:)
@@ -634,6 +515,7 @@ necessary but disallowed `HasTrie` constraints on the domain type.
634515
635516-}
636517
518+
637519---- To go elsewhere
638520
639521-- Matt Hellige's notation for @argument f . result g@.
@@ -649,92 +531,3 @@ f1 n = n + n
649531
650532f1' = memo f1
651533-}
652−
653−-- | just like @void@
654−instance HasTrie (V1 x) where
655− data (V1 x :->: b) = V1Trie
656− trie _ = V1Trie
657− untrie V1Trie = \ _ -> error "untrie V1Trie"
658− -- \case -- needs EmptyCase
659− enumerate V1Trie = []
660−
661−-- | just like @()@
662−instance HasTrie (U1 x) where
663− data (U1 x :->: b) = U1Trie b
664− trie f = U1Trie (f U1)
665− untrie (U1Trie b) = \U1 -> b
666− enumerate (U1Trie b) = [(U1, b)]
667−
668−-- | wraps @Either (f x) (g x)@
669−instance (HasTrie (f x), HasTrie (g x)) => HasTrie ((f :+: g) x) where
670− newtype ((f :+: g) x :->: b) = EitherTrie1 (Either (f x) (g x) :->: b)
671− trie f = EitherTrie1 (trie (f . liftSum))
672− untrie (EitherTrie1 t) = (untrie t) . dropSum
673− enumerate (EitherTrie1 t) = enum' liftSum t
674−
675−-- | wraps @(f x, g x)@
676−instance (HasTrie (f x), HasTrie (g x)) => HasTrie ((f :*: g) x) where
677− newtype ((f :*: g) x :->: b) = PairTrie1 ((f x, g x) :->: b)
678− trie f = PairTrie1 (trie (f . liftProduct))
679− untrie (PairTrie1 t) = (untrie t) . dropProduct
680− enumerate (PairTrie1 t) = enum' liftProduct t
681−
682−-- | wraps @a@
683−instance (HasTrie a) => HasTrie (K1 i a x) where
684− data (K1 i a x :->: b) = K1Trie (a :->: b)
685− trie f = K1Trie (trie (f . K1))
686− untrie (K1Trie t) = \(K1 a) -> (untrie t) a
687− enumerate (K1Trie t) = enum' K1 t
688−
689−-- | wraps @f x@
690−instance (HasTrie (f x)) => HasTrie (M1 i t f x) where
691− data (M1 i t f x :->: b) = M1Trie (f x :->: b)
692− trie f = M1Trie (trie (f . M1))
693− untrie (M1Trie t) = \(M1 a) -> (untrie t) a
694− enumerate (M1Trie t) = enum' M1 t
695−
696−-- | the data type in a __reg__ular form.
697−-- "unlifted" generic representation. (i.e. is a unary type constructor).
698−type Reg a = Rep a ()
699−
700−-- | 'Generic'-friendly default for 'trie'
701−trieGeneric :: (Generic a, HasTrie (Reg a))
702− => ((Reg a :->: b) -> (a :->: b))
703− -> (a -> b)
704− -> (a :->: b)
705−trieGeneric theConstructor f = theConstructor (trie (f . to))
706−{-# INLINEABLE trieGeneric #-}
707−
708−-- | 'Generic'-friendly default for 'untrie'
709−untrieGeneric :: (Generic a, HasTrie (Reg a))
710− => ((a :->: b) -> (Reg a :->: b))
711− -> (a :->: b)
712− -> (a -> b)
713−untrieGeneric theDestructor t = \a -> (untrie (theDestructor t)) (from a)
714−{-# INLINEABLE untrieGeneric #-}
715−
716−-- | 'Generic'-friendly default for 'enumerate'
717−enumerateGeneric :: (Generic a, HasTrie (Reg a))
718− => ((a :->: b) -> (Reg a :->: b))
719− -> (a :->: b)
720− -> [(a, b)]
721−enumerateGeneric theDestructor t = enum' to (theDestructor t)
722−{-# INLINEABLE enumerateGeneric #-}
723−
724−dropProduct :: (f :*: g) a -> (f a, g a)
725−dropProduct (a :*: b) = (a, b)
726−{-# INLINEABLE dropProduct #-}
727−
728−liftProduct :: (f a, g a) -> (f :*: g) a
729−liftProduct (a, b) = (a :*: b)
730−{-# INLINEABLE liftProduct #-}
731−
732−dropSum :: (f :+: g) a -> Either (f a) (g a)
733−dropSum s = case s of
734− L1 x -> Left x
735− R1 x -> Right x
736−{-# INLINEABLE dropSum #-}
737−
738−liftSum :: Either (f a) (g a) -> (f :+: g) a
739−liftSum = either L1 R1
740−{-# INLINEABLE liftSum #-}
stack.yamldeleted−7
@@ -1,7 +0,0 @@
1−# resolver: lts-9.21 # ghc-8.0.2
2−# resolver: lts-11.22 # ghc-8.2.2
3−# resolver: lts-12.14 # ghc-8.4.3
4−# resolver: lts-12.19 # ghc-8.4.4
5−# resolver: lts-13.0 # ghc-8.6.3
6−# resolver: lts-13.13 # ghc-8.6.4
7−resolver: lts-14.6 # ghc-8.6.5
wikipage.twnew file+21
@@ -0,0 +1,21 @@
1+[[Category:Packages]]
2+
3+== Abstract ==
4+
5+'''MemoTrie''' is functional library for creating efficient memo functions, using [http://en.wikipedia.org/wiki/Trie trie]s. It's based on [http://hpaste.org/3839 some code] from Spencer Janssen and uses type families.
6+
7+Besides this wiki page, here are more ways to find out about MemoTrie:
8+* Visit the [http://hackage.haskell.org/cgi-bin/hackage-scripts/package/MemoTrie Hackage page] for library documentation and to download & install.
9+* Or install with <tt>cabal install MemoTrie</tt>.
10+* Get the code repository: <tt>darcs get http://code.haskell.org/MemoTrie</tt>.
11+<!-- * See the [[MemoTrie/Versions| version history]]. -->
12+
13+Please leave comments at the [[Talk:MemoTrie|Talk page]].
14+
15+== See also ==
16+
17+* [http://www.haskell.org/haskellwiki/GHC/Indexed_types#An_associated_data_type_example An associated data type example]
18+* Ralf Hinze's ''[http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.46.223 Generalizing Generalized Tries]''
19+* Related [http://conal.net/blog/tag/tries/ blog posts].
20+* Use of MemoTrie in [[vector-space]].
21+