@@ -9,7 +9,7 @@
99----------------------------------------------------------------------
1010-- |
1111-- Module : Data.MemoTrie
12−-- Copyright : (c) Conal Elliott 2008-2016
12+-- Copyright : (c) Conal Elliott 2008-2012
1313-- License : BSD3
1414--
1515-- Maintainer : conal@conal.net
@@ -55,28 +55,22 @@ module Data.MemoTrie
5555 , memo, memo2, memo3, mup
5656 , inTrie, inTrie2, inTrie3
5757 -- , untrieBits
58− , trieGeneric, untrieGeneric, enumerateGeneric, Reg
59− , memoFix
58+ , trieGeneric, untrieGeneric, enumerateGeneric, Reg
6059 ) where
6160
6261-- Export the parts of HasTrie separately in order to get the associated data
6362-- type constructors, so I can define instances of other classes on them.
6463
65−import Data.Function (fix)
6664import Data.Bits
6765import Data.Word
6866import Data.Int
69−#if !MIN_VERSION_base(4,8,0)
70−import Control.Applicative
71−#endif
67+-- import Control.Applicative
7268import Control.Arrow (first,(&&&))
73−#if !MIN_VERSION_base(4,8,0)
74−import Data.Monoid
75−#endif
69+-- import Data.Monoid
7670import Data.Function (on)
7771import GHC.Generics
7872
79−import Control.Newtype.Generics
73+import Control.Newtype
8074
8175import Data.Void (Void)
8276
@@ -170,42 +164,6 @@ mup mem f = memo (mem . f)
170164memo2 = mup memo
171165memo3 = mup memo2
172166
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−
209167-- | Apply a unary function inside of a trie
210168inTrie :: (HasTrie a, HasTrie c) =>
211169 ((a -> b) -> (c -> d))
@@ -315,16 +273,6 @@ if' _ e True = e
315273 BoolTrie f t
316274-}
317275
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)
328276
329277instance (HasTrie a, HasTrie b) => HasTrie (Either a b) where
330278 data (Either a b) :->: x = EitherTrie (a :->: x) (b :->: x)
@@ -587,12 +535,7 @@ instance HasTrie a => Monad ((:->:) a) where
587535
588536instance (HasTrie a, Monoid b) => Monoid (a :->: b) where
589537 mempty = trie mempty
590−#if !MIN_VERSION_base(4,11,0)
591538 mappend = inTrie2 mappend
592−#else
593−instance (HasTrie a, Semigroup b) => Semigroup (a :->: b) where
594− (<>) = inTrie2 (<>)
595−#endif
596539
597540instance HasTrie a => Functor ((:->:) a) where
598541 fmap f = inTrie (fmap f)
@@ -738,3 +681,4 @@ dropSum s = case s of
738681liftSum :: Either (f a) (g a) -> (f :+: g) a
739682liftSum = either L1 R1
740683{-# INLINEABLE liftSum #-}
684+