functor-combo 0.1.0 → 0.1.1
raw patch · 3 files changed
+54/−8 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ FunctorCombo.Functor: (:#) :: a -> a -> Pair a
+ FunctorCombo.Functor: data Pair a
+ FunctorCombo.Functor: instance Applicative Pair
+ FunctorCombo.Functor: instance Foldable Pair
+ FunctorCombo.Functor: instance Functor Pair
+ FunctorCombo.Functor: instance Monad Pair
+ FunctorCombo.Functor: instance Traversable Pair
+ FunctorCombo.StrictMemo: instance (HasTrie a, Functor (Trie a)) => HasTrie (Pair a)
- FunctorCombo.DHoley: class Functor f => Holey f where { type family Der f :: * -> *; }
+ FunctorCombo.DHoley: class Functor f => Holey f where type family Der f :: * -> *
- FunctorCombo.Functor: newtype (:.) g :: (* -> *) f :: (* -> *) a :: (* -> *) -> (* -> *) -> * -> *
+ FunctorCombo.Functor: newtype (:.) (g :: * -> *) (f :: * -> *) a :: (* -> *) -> (* -> *) -> * -> *
- FunctorCombo.NonstrictMemo: class Functor (STrie (k)) => HasTrie k where { type family STrie k :: * -> *; }
+ FunctorCombo.NonstrictMemo: class Functor (STrie (k)) => HasTrie k where type family STrie k :: * -> *
- FunctorCombo.Regular: class Functor (PF t) => Regular t where { type family PF t :: * -> *; }
+ FunctorCombo.Regular: class Functor (PF t) => Regular t where type family PF t :: * -> *
- FunctorCombo.StrictMemo: class HasTrie k where { type family Trie k :: * -> *; }
+ FunctorCombo.StrictMemo: class HasTrie k where type family Trie k :: * -> *
Files
- functor-combo.cabal +2/−2
- src/FunctorCombo/Functor.hs +33/−0
- src/FunctorCombo/StrictMemo.hs +19/−6
functor-combo.cabal view
@@ -1,5 +1,5 @@ Name: functor-combo-Version: 0.1.0+Version: 0.1.1 Cabal-Version: >= 1.2 Synopsis: Functor combinators with tries & zippers Category: Data@@ -10,7 +10,7 @@ Author: Conal Elliott Maintainer: conal@conal.net Homepage: http://haskell.org/haskellwiki/functor-combo-Copyright: (c) 2010 by Conal Elliott+Copyright: (c) 2010-2012 by Conal Elliott License: BSD3 License-File: COPYING Stability: experimental
src/FunctorCombo/Functor.hs view
@@ -19,6 +19,7 @@ , (:*:)(..),fstF,sndF,(:.)(..),unO,inO,inO2,(~>) , Lift(..), (:*:!)(..), (:+:!)(..), eitherF' , pairF, unPairF, inProd, inProd2+ , Pair(..) ) where @@ -264,3 +265,35 @@ eitherF' :: (f a -> c) -> (g a -> c) -> ((f :+:! g) a -> c) eitherF' p _ (InL' fa) = p fa eitherF' _ q (InR' ga) = q ga++{--------------------------------------------------------------------+ Pair functor. Just a convenience. Pair =~ Id :*: Id+--------------------------------------------------------------------}++-- | Uniform pairs+data Pair a = a :# a++-- Interpreting Pair a as Bool -> a or as Vec2 a, the instances follow+-- inevitably from the principle of type class morphisms.++instance Functor Pair where+ fmap f (a :# b) = (f a :# f b)++instance Applicative Pair where+ pure a = (a :# a)+ (f :# g) <*> (a :# b) = (f a :# g b)++instance Monad Pair where+ return = pure+ (a :# b) >>= f = (c :# d)+ where+ (c :# _) = f a+ (_ :# d) = f b++instance Foldable Pair where+ foldMap f (a :# b) = f a `mappend` f b+ -- fold (a :# b) = a `mappend` b++instance Traversable Pair where+ traverse h (fa :# fb) = liftA2 (:#) (h fa) (h fb)+ -- sequenceA (fa :# fb) = liftA2 (:#) fa fb
src/FunctorCombo/StrictMemo.hs view
@@ -6,7 +6,7 @@ ---------------------------------------------------------------------- -- | -- Module : FunctorCombo.MemoTrie--- Copyright : (c) Conal Elliott 2010+-- Copyright : (c) Conal Elliott 2010-2012 -- License : BSD3 -- -- Maintainer : conal@conal.net@@ -60,8 +60,6 @@ #endif -- -- | Domain types with associated memo tries class HasTrieContext(k) => HasTrie k where -- | Representation of trie with domain type @a@@@ -145,6 +143,8 @@ trie f = O (trie (trie . curry f)) -- untrie (O tt) = uncurry (untrie . untrie tt) untrie (O tt) = uncurry (untrie (fmap untrie tt))+ -- With the first form of untrie, I only need HasTrie a, not also+ -- Functor (Trie a) in the case of FunctorSuperClass -- enumerate (O tt) = -- [ ((a,b),x) | (a,t) <- enumerate tt , (b,x) <- enumerate t ] @@ -159,10 +159,14 @@ -- enumerate = (result.fmap.first) (fromIso) enumerate; +-- HasTrieIsomorph( (), Bool, Either () ()+-- , bool (Right ()) (Left ())+-- , either (\ () -> False) (\ () -> True)) -HasTrieIsomorph( (), Bool, Either () ()- , bool (Right ()) (Left ())- , either (\ () -> False) (\ () -> True))+instance HasTrie Bool where+ type Trie Bool = Pair+ trie f = (f False :# f True)+ untrie (f :# t) c = if c then t else f HasTrieIsomorph( (HF(a),HF(b), HasTrie c) , (a,b,c), ((a,b),c)@@ -333,6 +337,15 @@ HasTrieIsomorph((HasTrie a, HasTrie (a :->: b)), a -> b, a :->: b, trie, untrie) +-- -- Convenience Pair functor+-- instance HasTrie a => HasTrie (Pair a) where+-- type Trie (Pair a) = Trie a :. Trie a+-- trie f = O (trie (\ a -> trie (\ b -> f (a :# b))))+-- untrie (O tt) (a :# b) = untrie (untrie tt a) b++HasTrieIsomorph((HF(a))+ , Pair a, (a,a)+ , \ (a :# a') -> (a,a'), \ (a,a') -> (a :# a')) {-------------------------------------------------------------------- Misc