functor-combo 0.0.1 → 0.0.2
raw patch · 4 files changed
+41/−18 lines, 4 files
Files
- functor-combo.cabal +1/−1
- src/FunctorCombo/DHoley.hs +6/−3
- src/FunctorCombo/Functor.hs +1/−1
- src/FunctorCombo/MemoTrie.hs +33/−13
functor-combo.cabal view
@@ -1,5 +1,5 @@ Name: functor-combo-Version: 0.0.1+Version: 0.0.2 Cabal-Version: >= 1.2 Synopsis: Functor combinators with tries & zippers Category: Data
src/FunctorCombo/DHoley.hs view
@@ -29,9 +29,12 @@ type Loc f a = (Der f a, a) class Functor f => Holey f where- type Der f :: * -> * -- ^ Derivative, i.e., one-hole context- fill :: Loc f a -> f a -- ^ Fill a hole- extract :: f a -> f (Loc f a) -- ^ All extractions+ -- | Derivative, i.e., one-hole context+ type Der f :: * -> *+ -- | Fill a hole+ fill :: Loc f a -> f a+ -- | All extractions+ extract :: f a -> f (Loc f a) -- The Functor constraint simplifies several signatures below. instance Holey (Const z) where
src/FunctorCombo/Functor.hs view
@@ -41,7 +41,7 @@ -- From Control.Compose: -- --- data Id a = Id a+-- newtype Id a = Id a -- | Product on unary type constructors data (f :*: g) a = f a :*: g a deriving (Show)
src/FunctorCombo/MemoTrie.hs view
@@ -13,8 +13,6 @@ -- -- Functor-based memo tries (strict for now) -- --- Warning: this formulation cannot handle recursive types.--- The type checker fails to terminate. Wondering about solutions. ---------------------------------------------------------------------- module FunctorCombo.MemoTrie@@ -275,38 +273,60 @@ {- -ft1 :: (Bool -> a) -> (a,a)-ft1 f = (f False, f True)+ft1 :: (Bool -> a) -> [a]+ft1 f = [f False, f True] f1 :: Bool -> Int f1 False = 0 f1 True = 1 -trie1a :: (Bool -> Int) :->: (Int, Int)+trie1a :: HasTrie a => (Bool -> a) :->: [a] trie1a = trie ft1 -trie1b :: (Bool :->: Int) :->: (Int, Int)+trie1b :: HasTrie a => (Bool :->: a) :->: [a] trie1b = trie1a -trie1c :: (Either () () :->: Int) :->: (Int, Int)+trie1c :: HasTrie a => (Either () () :->: a) :->: [a] trie1c = trie1a -trie1d :: ((Trie () :*: Trie ()) Int) :->: (Int, Int)+trie1d :: HasTrie a => ((Trie () :*: Trie ()) a) :->: [a] trie1d = trie1a -trie1e :: (Trie () Int, Trie () Int) :->: (Int, Int)+trie1e :: HasTrie a => (Trie () a, Trie () a) :->: [a] trie1e = trie1a -trie1f :: (() :->: Int, () :->: Int) :->: (Int, Int)+trie1f :: HasTrie a => (() :->: a, () :->: a) :->: [a] trie1f = trie1a -trie1g :: (Int, Int) :->: (Int, Int)+trie1g :: HasTrie a => (a, a) :->: [a] trie1g = trie1a -trie1h :: (Trie Int :. Trie Int) (Int, Int)+trie1h :: HasTrie a => (Trie a :. Trie a) [a] trie1h = trie1a -trie1i :: Int :->: Int :->: (Int, Int)+trie1i :: HasTrie a => a :->: a :->: [a] trie1i = unO trie1a++-}++{-++ft2 :: ([Bool] -> Int) -> Int+ft2 f = f (alts 15)++alts :: Int -> [Bool]+alts n = take n (cycle [True,False])++f2 :: [Bool] -> Int+f2 = length . filter id++-- Memoization fails:++-- *FunctorCombo.MemoTrie> ft2 f2+-- 8+-- *FunctorCombo.MemoTrie> memo ft2 f2+-- ... (hang forever) ...++-- Would nonstrict memoization work? <http://conal.net/blog/posts/nonstrict-memoization/> -}