pointless-haskell 0.0.4 → 0.0.5
raw patch · 6 files changed
+51/−30 lines, 6 files
Files
- pointless-haskell.cabal +2/−2
- src/Generics/Pointless/Combinators.hs +24/−5
- src/Generics/Pointless/Examples/Examples.hs +10/−10
- src/Generics/Pointless/Fctrable.hs +1/−0
- src/Generics/Pointless/Functors.hs +12/−12
- src/Generics/Pointless/Observe/Functors.hs +2/−1
pointless-haskell.cabal view
@@ -1,5 +1,5 @@ Name: pointless-haskell-Version: 0.0.4+Version: 0.0.5 License: BSD3 License-file: LICENSE Author: Alcino Cunha <alcino@di.uminho.pt>, Hugo Pacheco <hpacheco@di.uminho.pt>@@ -27,12 +27,12 @@ exposed-modules: Generics.Pointless.Combinators Generics.Pointless.Functors,+ Generics.Pointless.Fctrable, Generics.Pointless.RecursionPatterns, Generics.Pointless.Observe.Functors, Generics.Pointless.Observe.RecursionPatterns, Generics.Pointless.Examples.Examples, Generics.Pointless.Examples.Observe,- Generics.Pointless.Fctrable, Generics.Pointless.MonadCombinators, Generics.Pointless.Bifunctors, Generics.Pointless.Bifctrable
src/Generics/Pointless/Combinators.hs view
@@ -87,7 +87,7 @@ -- * Exponentials -- | The application combinator.-app :: (a -> b, a) -> b+app :: (a -> b,a) -> b app (f,x) = f x -- | The left exponentiation combinator.@@ -109,10 +109,13 @@ grd :: (a -> Bool) -> a -> Either a a grd p x = if p x then inl x else inr x --- | Infix guarc combinator that simulates the postfix syntax.+-- | Infix guard combinator that simulates the postfix syntax. (?) :: (a -> Bool) -> a -> Either a a (?) = grd +infix 1 ??+(??) :: (a -> Either One One) -> a -> Either a a+(??) p = (snd -|- snd) . distl . (p /\ id) -- * Point-free definitions of uncurried versions of the basic combinators -- | The uncurried split combinator.@@ -162,7 +165,7 @@ coswap = inr \/ inl -- | Distribute products over the left of sums.-distl :: (Either a b, c) -> Either (a,c) (b,c)+distl :: (Either a b,c) -> Either (a,c) (b,c) distl = app . ((curry inl \/ curry inr) >< id) -- | Distribute sums over the left of products.@@ -179,11 +182,11 @@ -- | Associate nested products to the left. assocl :: (a,(b,c)) -> ((a,b),c)-assocl = id >< fst /\ snd . snd+assocl = (id >< fst) /\ snd . snd -- | Associates nested products to the right. assocr :: ((a,b),c) -> (a,(b,c))-assocr = fst . fst /\ snd >< id+assocr = fst . fst /\ (snd >< id) -- | Associates nested sums to the left. coassocl :: Either a (Either b c) -> Either (Either a b) c@@ -192,6 +195,22 @@ -- | Associates nested sums to the right. coassocr :: Either (Either a b) c -> Either a (Either b c) coassocr = (id -|- inl) \/ (inr . inr)++-- | Shifts the an element to the right of a nested pair.+subr :: (a,(b,c)) -> (b,(a,c))+subr = assocr . (swap >< id) . assocl++-- | Shifts the an element to the left of a nested pair.+subl :: ((a,b),c) -> ((a,c),b)+subl = assocl . (id >< swap) . assocr++-- | Shifts an option to the right of a nested sum.+cosubr :: Either a (Either b c) -> Either b (Either a c)+cosubr = coassocr . (coswap -|- id) . coassocl++-- | Shifts an option to the left of a nested sum.+cosubl :: Either (Either a b) c -> Either (Either a c) b+cosubl = coassocl . (id -|- coswap) . coassocr -- | The product distribution combinator distp :: ((c,d),(a,b)) -> ((c,a),(d,b))
src/Generics/Pointless/Examples/Examples.hs view
@@ -323,7 +323,7 @@ -- | Append an element to the end of a list as an hylomorphism. snoc :: (a,[a]) -> [a] snoc = hylo (_L::NeList a a) f g- where g = (fst -|- assocr . (swap >< id) . assocl) . distr . (id >< out)+ where g = (fst -|- subr) . distr . (id >< out) f = wrap \/ cons -- | Append an element to the end of a list as an apomorphism.@@ -371,24 +371,24 @@ fisum = cata (_L::[Int]) f where f = pnt (nil . bang) \/ comp . swap . (curry add >< (cons .) . split . (pnt id . bang /\ id)) -data NeLis a = Wrap a | NeCons a (NeLis a) deriving (Eq,Show)-type instance PF (NeLis a) = Const a :+: Const a :*: Id-instance Mu (NeLis a) where+data Some a = Wrap a | Insert a (Some a) deriving (Eq,Show)+type instance PF (Some a) = Const a :+: Const a :*: Id+instance Mu (Some a) where inn (Left x) = Wrap x- inn (Right (x,xs)) = NeCons x xs+ inn (Right (x,xs)) = Insert x xs out (Wrap x) = Left x- out (NeCons x xs) = Right (x,xs)-neCons = uncurry NeCons+ out (Insert x xs) = Right (x,xs)+neCons = uncurry Insert -- | Incrementation the elements of a list by a specified value as an accumulation. -- The result is always a non-empty list-isumsAccum :: ([Int],Int) -> NeLis Int+isumsAccum :: ([Int],Int) -> Some Int isumsAccum = accum _L h tau where h = inn . (snd -|- swap . (snd >< id)) . distl tau = (fst -|- aux) . distl aux = assocr . (fst /\ addAccum . (fst >< id)) -isumsAna :: ([Int],Int) -> NeLis Int+isumsAna :: ([Int],Int) -> Some Int isumsAna = ana _L h where h = (snd -|- (snd /\ aux)) . distl . (out >< id) aux = (id >< addAccum) . assocr . (swap >< id)@@ -622,7 +622,7 @@ -- | Definition of a stream sequence generator as an anamorphism. generate :: Int -> Stream Int-generate = ana (_L::Stream Int) (id /\ succ)+generate = ana (_L::Stream a) (id /\ succ) -- | Identity o streams as an anamorphism. idStream :: Stream a -> Stream a
src/Generics/Pointless/Fctrable.hs view
@@ -18,6 +18,7 @@ module Generics.Pointless.Fctrable where import Prelude hiding (Functor(..),fmap)+ import Generics.Pointless.Functors import Generics.Pointless.Combinators
src/Generics/Pointless/Functors.hs view
@@ -28,32 +28,32 @@ -- ** Definition and operations over functors -- | Identity functor.-newtype Id x = Id {unId :: x}+newtype Id x = IdF {unIdF :: x} -- | Constant functor.-newtype Const t x = Cons {unCons :: t}+newtype Const t x = ConsF {unConsF :: t} -- | Sum of functors. infixr 5 :+:-data (g :+: h) x = Inl (g x) | Inr (h x)+data (g :+: h) x = InlF (g x) | InrF (h x) -- | Product of functors. infixr 6 :*:-data (g :*: h) x = Prod (g x) (h x)+data (g :*: h) x = ProdF (g x) (h x) -- | Composition of functors. infixr 9 :@:-newtype (g :@: h) x = Comp {unComp :: g (h x)}+newtype (g :@: h) x = CompF {unCompF :: g (h x)} -- | Explicit fixpoint operator.-newtype Fix f = Fix { -- | The unfolding of the fixpoint of a functor is the functor applied to its fixpoint.+newtype Fix f = FixF { -- | The unfolding of the fixpoint of a functor is the functor applied to its fixpoint. -- -- 'unFix' is specialized with the application of 'Rep' in order to subsume functor application- unFix :: Rep f (Fix f)+ unFixF :: Rep f (Fix f) } instance Show (Rep f (Fix f)) => Show (Fix f) where- show (Fix f) = "(Fix " ++ show f ++ ")"+ show (FixF f) = "(Fix " ++ show f ++ ")" -- | Family of patterns functors of data types. --@@ -92,7 +92,7 @@ -- | Polytypic 'Prelude.Functor' class for functor representations class Functor (f :: * -> *) where- fmap :: Fix f -- ^ For desambiguation purposes, the type of the functor must be passed as an explicit paramaeter to 'fmap'+ fmap :: Fix f -- ^ For desambiguation purposes, the type of the functor must be passed as an explicit parameter to 'fmap' -> (x -> y) -> Rep f x -> Rep f y -- ^ The mapping over representations instance Functor Id where@@ -136,8 +136,8 @@ out :: a -> F a a instance Mu (Fix f) where- inn = Fix- out = unFix+ inn = FixF+ out = unFixF -- ^ Expanding/contracting the fixed point of a functor is the same as consuming/applying it's single type constructor -- ** Fixpoint combinators@@ -207,7 +207,7 @@ -- ** Natural Numbers -data Nat = Zero | Succ Nat deriving (Eq,Show)+data Nat = Zero | Succ Nat deriving (Eq,Show,Read) type instance PF Nat = Const One :+: Id
src/Generics/Pointless/Observe/Functors.hs view
@@ -104,7 +104,8 @@ -- where thk = thunk :: a -> ObserverM a instance (Functor f, FunctorO f) => Observable (Fix f) where- observer (Fix x) = send (watch (_L::Fix f) (_L::Fix f) x) (liftM Fix (fmapO (_L :: Fix f) thk x))++ observer (FixF x) = send (watch (_L::Fix f) (_L::Fix f) x) (liftM FixF (fmapO (_L :: Fix f) thk x)) where thk = thunk :: Fix f -> ObserverM (Fix f)