packages feed

free-functors 0.3 → 0.4

raw patch · 3 files changed

+48/−14 lines, 3 filesdep ~algebraic-classesPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: algebraic-classes

API changes (from Hackage documentation)

- Data.Functor.Free: fstP :: c m => Free c (m, n) -> m
- Data.Functor.Free: product :: (r -> m) -> (r -> n) -> r -> Free c (m, n)
- Data.Functor.Free: sndP :: c n => Free c (m, n) -> n

Files

+ examples/Parser.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE +    FlexibleInstances +  , TypeOperators+  , GADTs+  , TypeSynonymInstances+  , LambdaCase+  #-}+module FreeNum where++import Data.Functor.HFree++import Control.Applicative+import Control.Monad+import Control.Monad.Trans.State++data ParserF c a where+  Symbol :: c -> ParserF c c++type Parser c = HFree Alternative (ParserF c)++symbol :: c -> Parser (ParserF c) c+symbol = liftFree . Symbol+++parseF :: Eq c => ParserF c :~> StateT [c] Maybe+parseF (Symbol c) = StateT $ \case+  (a:as) | c == a -> Just (a, as)+  _ -> Nothing++parse :: Eq c => Parser c a -> [c] -> Maybe a+parse p = fmap fst . mfilter (null . snd) . runStateT (rightAdjunct parseF p)+++parenDepth :: Parser Char Int+parenDepth = maximum . (0:) <$> many (succ <$> (symbol '(' *> parenDepth <* symbol ')'))++maxDepth :: String -> Maybe Int+maxDepth = parse parenDepth
free-functors.cabal view
@@ -1,12 +1,12 @@ name:                free-functors-version:             0.3+version:             0.4 synopsis:            Provides free functors that are adjoint to functors that forget class constraints.  description:         A free functor is a left adjoint to a forgetful functor. It used to be the case                      that the only category that was easy to work with in Haskell was Hask itself, so                      there were no interesting forgetful functors.                      .                      But the new ConstraintKinds feature of GHC provides an easy way of creating-                     subclasses of Hask. That brings interesting opportunities for free (and cofree) functors.+                     subcategories of Hask. That brings interesting opportunities for free (and cofree) functors.                      .                      The examples directory contains an implementation of non-empty lists as free semigroups,                      and automata as free actions. The standard example of free higher order functors is free monads,@@ -45,7 +45,7 @@     transformers >= 0.2.0.0 && < 0.4,     comonad >= 3.0 && < 3.1,     void >= 0.4 && < 0.7,-    algebraic-classes == 0.1.*+    algebraic-classes >= 0.1 && < 0.3  source-repository head   type:     git
src/Data/Functor/Free.hs view
@@ -110,11 +110,11 @@ convertClosed :: c r => Free c Void -> r convertClosed = rightAdjunct absurd -type InitialObject c = Free c Void--initial :: c r => InitialObject c -> r-initial = rightAdjunct absurd+-- * Coproducts +-- | Products of @Monoid@s are @Monoid@s themselves. But coproducts of @Monoid@s are not. +-- However, the free @Monoid@ applied to the coproduct /is/ a @Monoid@, and it is the coproduct in the category of @Monoid@s.+-- This is also called the free product, and generalizes to any algebraic class. type Coproduct c m n = Free c (Either m n)  coproduct :: c r => (m -> r) -> (n -> r) -> Coproduct c m n -> r@@ -126,11 +126,7 @@ inR :: c n => n -> Coproduct c m n inR = unit . Right -product :: (r -> m) -> (r -> n) -> r -> Free c (m, n)-product m n r = unit (m r, n r)--fstP :: c m => Free c (m, n) -> m-fstP = rightAdjunct fst+type InitialObject c = Free c Void -sndP :: c n => Free c (m, n) -> n-sndP = rightAdjunct snd+initial :: c r => InitialObject c -> r+initial = rightAdjunct absurd