packages feed

pointless-haskell 0.0.3 → 0.0.4

raw patch · 3 files changed

+49/−4 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Generics.Pointless.Examples.Examples: reverseAna :: [a] -> [a]
+ Generics.Pointless.Combinators: distp :: ((c, d), (a, b)) -> ((c, a), (d, b))
+ Generics.Pointless.Combinators: dists :: (Either a b, Either c d) -> Either (Either (a, c) (a, d)) (Either (b, c) (b, d))
+ Generics.Pointless.Examples.Examples: NeCons :: a -> (NeLis a) -> NeLis a
+ Generics.Pointless.Examples.Examples: Wrap :: a -> NeLis a
+ Generics.Pointless.Examples.Examples: data NeLis a
+ Generics.Pointless.Examples.Examples: instance (Eq a) => Eq (NeLis a)
+ Generics.Pointless.Examples.Examples: instance (Show a) => Show (NeLis a)
+ Generics.Pointless.Examples.Examples: instance Mu (NeLis a)
+ Generics.Pointless.Examples.Examples: isumsAccum :: ([Int], Int) -> NeLis Int
+ Generics.Pointless.Examples.Examples: isumsAna :: ([Int], Int) -> NeLis Int
+ Generics.Pointless.Examples.Examples: reverseAccum' :: ([a], [a]) -> [a]
+ Generics.Pointless.Examples.Examples: reverseCata :: [a] -> [a]
+ Generics.Pointless.Examples.Examples: reverseHylo :: ([a], [a]) -> [a]

Files

pointless-haskell.cabal view
@@ -1,5 +1,5 @@ Name:            pointless-haskell-Version:         0.0.3+Version:         0.0.4 License:         BSD3 License-file:    LICENSE Author:          Alcino Cunha <alcino@di.uminho.pt>, Hugo Pacheco <hpacheco@di.uminho.pt>
src/Generics/Pointless/Combinators.hs view
@@ -193,3 +193,10 @@ coassocr :: Either (Either a b) c -> Either a (Either b c) coassocr = (id -|- inl) \/ (inr . inr) +-- | The product distribution combinator+distp :: ((c,d),(a,b)) -> ((c,a),(d,b))+distp = fst >< fst /\ snd >< snd++-- | The sum distribution combinator.+dists :: (Either a b,Either c d) -> Either (Either (a,c) (a,d)) (Either (b,c) (b,d))+dists = (distr -|- distr) . distl
src/Generics/Pointless/Examples/Examples.hs view
@@ -366,20 +366,58 @@    where f = nil \/ isumOp . swap . (id >< cons . (zero . bang /\ id))          isumOp (l,x) = map (x+) l --- | Incrementation the elements of a list by a specified value a catamorphism.+-- | Incrementation the elements of a list by a specified value as a catamorphism. fisum :: [Int] -> Int -> [Int] 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+    inn (Left x) = Wrap x+    inn (Right (x,xs)) = NeCons x xs+    out (Wrap x) = Left x+    out (NeCons x xs) = Right (x,xs)+neCons = uncurry NeCons++-- | 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 = 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 = ana _L h+    where h = (snd -|- (snd /\ aux)) . distl . (out >< id)+          aux = (id >< addAccum) . assocr . (swap >< id)+ -- | Definition of list mapping as a catamorphism. mapCata :: [a] -> (a -> b) -> [b] mapCata = cata (_L::[a]) f    where f = (([]!)!) \/ curry (cons . (app . swap >< app) . ((fst >< id) /\ (snd >< id)))  -- | Definition of list reversion as a catamorphism.-reverseAna :: [a] -> [a]-reverseAna = cata (_L::[a]) f +reverseCata :: [a] -> [a]+reverseCata = cata (_L::[a]) f      where f = nil \/ (cat . swap . (wrap >< id))++-- | Linear version of reverse using accumulations+reverseAccum l = reverseAccum' (l,[])++reverseAccum' :: ([a],[a]) -> [a]+reverseAccum' = accum (_L ::[a]) h tau+    where h = (snd \/ snd . fst) . distl+          tau = (fst -|- aux) . distl+          aux = assocr . (id >< cons) . distp . ((id /\ id) >< id) . assocr++reverseHylo :: ([a],[a]) -> [a]+reverseHylo = hylo t g h+    where g = id \/ id+          h = (snd -|- aux) . distl . (out >< id)+          aux = (id >< inn . inr) . assocr . (swap >< id)+          t = _L :: K [a] :+!: I  -- | Definition of the quicksort algorithm as an hylomorphism. qsort :: (Ord a) => [a] -> [a]