packages feed

bf-cata 1.0 → 1.1

raw patch · 2 files changed

+31/−27 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.BreadthFirstCata.Cata: Sem :: (Inh n -> Comp i n) -> Sem i n
- Data.BreadthFirstCata.Cata: newtype Sem i n
+ Data.BreadthFirstCata.Cata: Child :: (Inh n -> Comp i n) -> Child i n
+ Data.BreadthFirstCata.Cata: newtype Child i n
- Data.BreadthFirstCata.Cata: Fin :: (Syn a) -> Outcome i a
+ Data.BreadthFirstCata.Cata: Fin :: !Syn n -> Outcome i n
- Data.BreadthFirstCata.Cata: Step :: i -> (Comp i a) -> Outcome i a
+ Data.BreadthFirstCata.Cata: Step :: !i -> (Comp i n) -> Outcome i n
- Data.BreadthFirstCata.Cata: data Outcome i a
+ Data.BreadthFirstCata.Cata: data Outcome i n
- Data.BreadthFirstCata.Cata: invoke :: Sem i n -> Inh n -> Comp i n
+ Data.BreadthFirstCata.Cata: invoke :: Child i n -> Inh n -> Comp i n
- Data.BreadthFirstCata.Cata: lazyEval :: Comp i a -> Syn a
+ Data.BreadthFirstCata.Cata: lazyEval :: Comp i n -> Syn n
- Data.BreadthFirstCata.Cata: oneStep :: Comp i a -> Outcome i a
+ Data.BreadthFirstCata.Cata: oneStep :: Comp i n -> Outcome i n
- Data.BreadthFirstCata.Cata: resume :: Comp i m -> (Syn m -> Comp i n) -> Comp i n
+ Data.BreadthFirstCata.Cata: resume :: Comp i n' -> (Syn n' -> Comp i n) -> Comp i n
- Data.BreadthFirstCata.Cata: sem_Inject :: Sem i Inject
+ Data.BreadthFirstCata.Cata: sem_Inject :: Child i Inject

Files

bf-cata.cabal view
@@ -1,7 +1,7 @@ cabal-version: >=1.2 build-type: Simple name: bf-cata-version: 1.0+version: 1.1 license: LGPL maintainer: Arie Middelkoop <ariem@cs.uu.nl> homepage: http://www.cs.uu.nl/wiki/HUT/WebHome
src/Data/BreadthFirstCata/Cata.hs view
@@ -7,16 +7,19 @@ -- is made, evaluation proceeds lazily. -- What constitutes to be a step is determined by the callee. -{-# LANGUAGE GADTs, TypeFamilies, EmptyDataDecls #-}-module Data.BreadthFirstCata.Cata (Sem(Sem),Inh,Syn,Comp,invoke,final,info,resume,inject,sem_Inject,Inject,lazyEval,oneStep,Outcome(Step,Fin)) where+{-# LANGUAGE GADTs, TypeFamilies, EmptyDataDecls, RankNTypes, MultiParamTypeClasses, FlexibleInstances, BangPatterns #-}+module Data.BreadthFirstCata.Cata+  (Child(Child),Inh,Syn,Comp+  ,invoke,final,info,resume+  ,inject,sem_Inject,Inject,lazyEval,oneStep,Outcome(Step,Fin)) where  --- | Semantics of a nonterminal of type @n@ as a function from inherited+-- | Semantics of a child of type @n@ as a function from inherited -- attributes (@Inh n@) to a computation @Comp i n@ of synthesized attributes (@Syn n@). -newtype Sem i n = Sem (Inh n -> Comp i n)-data family Inh n    -- index @n@ uniquely determines the type of the inherited and-data family Syn n    -- synthesized attributes.+newtype Child i n = Child (Inh n -> Comp i n)+data family Inh n :: *         -- index @n@ uniquely determines the type of the inherited and+data family Syn n :: *         -- synthesized attributes.   -- | Computation of synthesized attributes of nonterminal of type @n@.@@ -27,9 +30,9 @@ -- gradually rewriting the latter, until it results in a @Final@.  data Comp i n where-  Pending :: Parents i m n -> Comp i m -> Comp i n-  Final   :: Syn n -> Comp i n-  Info    :: i -> Comp i n -> Comp i n+  Pending :: !(Parents i n' n) -> Comp i n' -> Comp i n+  Final   :: !(Syn n) -> Comp i n+  Info    :: !i -> Comp i n -> Comp i n   -- | Given a node of type @m@ that is currently being evaluated for a@@ -38,8 +41,8 @@ -- The outermost @Cont@-value) is the top of the stack, i.e. the direct -- parent of the formerly mentioned node. -data Parents i m n where-  Cont :: Node i m k -> Parents i k n -> Parents i m n+data Parents i n' n where+  Cont :: !(Node i n' k) -> !(Parents i k n) -> Parents i n' n   Root :: Parents i n n  @@ -48,19 +51,19 @@ -- (still needed) results of already constructed children and local -- attributes. -newtype Node i m n = Node (Syn m -> Comp i n)+newtype Node i n' n = Node (Syn n' -> Comp i n)   -- | Lazy evaluation of a computation. -- Note: we cannot inspect the effect-trace, as it would sequentialize -- the evaluation of children. -lazyEval :: Comp i a -> Syn a+lazyEval :: Comp i n -> Syn n lazyEval (Pending stack r) = evalParents stack (lazyEval r) lazyEval (Final v)  = v lazyEval (Info _ r) = lazyEval r -evalParents :: Parents i m n -> Syn m -> Syn n+evalParents :: Parents i n' n -> Syn n' -> Syn n evalParents Root v = v evalParents (Cont (Node f) c) v = evalParents c (lazyEval (f v)) @@ -70,15 +73,15 @@ -- depends on the application: evaluation proceeds until -- an outcome can be given. -data Outcome i a-  = Fin  (Syn a)-  | Step i (Comp i a)+data Outcome i n+  = Fin  !(Syn n)+  | Step !i (Comp i n)   -- | One step strict evaluation. Reduction proceeds until -- the computation is either finished or yields an @Info@-effect. -oneStep :: Comp i a -> Outcome i a+oneStep :: Comp i n -> Outcome i n oneStep (Pending stack r)   = case oneStep r of       Fin v     -> oneStep (reduceParent stack v)@@ -86,15 +89,16 @@ oneStep (Final v)  = Fin v oneStep (Info i r) = Step i r -reduceParent :: Parents i m n -> Syn m -> Comp i n+reduceParent :: Parents i n' n -> Syn n' -> Comp i n reduceParent Root v = Final v reduceParent (Cont (Node f) c) v = Pending c (f v)  --- | Unwrapper for @Sem@.-invoke :: Sem i n -> Inh n -> Comp i n-invoke (Sem f) = f+-- | Unwraps a @Child@+invoke :: Child i n -> Inh n -> Comp i n+invoke (Child f) inh = f inh + -- | Wrapper for final result. final :: Syn n -> Comp i n final = Final@@ -104,8 +108,8 @@ info = Info  -- | Create a |Pending| computation that waits for the given computation.-resume :: Comp i m -> (Syn m -> Comp i n) -> Comp i n-resume c k = Pending (Cont (Node k) Root) c+resume :: Comp i n' -> (Syn n' -> Comp i n) -> Comp i n+resume c !k = Pending (Cont (Node k) Root) c   -- | Injection of steps as conventional call@@ -114,8 +118,8 @@ data instance Inh Inject = Inh_Inject {} data instance Syn Inject = Syn_Inject {} -sem_Inject :: Sem i Inject-sem_Inject = Sem (const $ final $ Syn_Inject {})+sem_Inject :: Child i Inject+sem_Inject = Child (const $ final $ Syn_Inject {})  inject :: i -> Comp i Inject inject i = info i $ final $ Syn_Inject {}