From d17b6399f227ee6dfb6361638ad120d0f6cd82fb Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 22 Nov 2017 17:36:35 -0500 Subject: [PATCH] Specialize RAlgebra to use Base. --- src/Decorator.hs | 8 ++++---- src/Renderer/TOC.hs | 4 ++-- src/Semantic/Task.hs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Decorator.hs b/src/Decorator.hs index ec88e203f..5e233f2d2 100644 --- a/src/Decorator.hs +++ b/src/Decorator.hs @@ -35,15 +35,15 @@ import qualified Syntax as S type FAlgebra t a = Base t a -> a -- | An R-algebra on some carrier functor 'f' of its fixpoint type 't'. -type RAlgebra f t a = f (t, a) -> a +type RAlgebra t a = Base t (t, a) -> a -- | Promote an FAlgebra into an RAlgebra (by dropping the original parameter). -fToR :: Functor (Base t) => FAlgebra t a -> RAlgebra (Base t) t a +fToR :: Functor (Base t) => FAlgebra t a -> RAlgebra t a fToR f = f . fmap snd -- | Lift an algebra into a decorator for terms annotated with records. decoratorWithAlgebra :: Functor f - => RAlgebra (Base (Term f (Record fs))) (Term f (Record fs)) a -- ^ An R-algebra on terms. + => RAlgebra (Term f (Record fs)) a -- ^ An R-algebra on terms. -> Term f (Record fs) -- ^ A term to decorate with values produced by the R-algebra. -> Term f (Record (a ': fs)) -- ^ A term decorated with values produced by the R-algebra. decoratorWithAlgebra alg = para $ \ c@(In a f) -> termIn (alg (fmap (second (rhead . extract)) c) :. a) (fmap snd f) @@ -65,7 +65,7 @@ identifierAlgebra (In _ union) = case union of _ | Just Declaration.Method{..} <- prj union -> methodName _ -> Nothing -syntaxIdentifierAlgebra :: RAlgebra (TermF S.Syntax a) (Term S.Syntax a) (Maybe Identifier) +syntaxIdentifierAlgebra :: RAlgebra (Term S.Syntax a) (Maybe Identifier) syntaxIdentifierAlgebra (In _ syntax) = case syntax of S.Assignment f _ -> identifier f S.Class f _ _ -> identifier f diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index 882897770..13746a072 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -109,7 +109,7 @@ data Declaration -- If you’re getting errors about missing a 'CustomHasDeclaration' instance for your syntax type, you probably forgot step 1. -- -- If you’re getting 'Nothing' for your syntax node at runtime, you probably forgot step 2. -declarationAlgebra :: (HasField fields Range, HasField fields Span, Foldable syntax, HasDeclaration syntax) => Blob -> RAlgebra (TermF syntax (Record fields)) (Term syntax (Record fields)) (Maybe Declaration) +declarationAlgebra :: (HasField fields Range, HasField fields Span, Foldable syntax, HasDeclaration syntax) => Blob -> RAlgebra (Term syntax (Record fields)) (Maybe Declaration) declarationAlgebra blob (In ann syntax) = toDeclaration blob ann syntax @@ -224,7 +224,7 @@ declaration (In annotation _) = annotation <$ getDeclaration annotation -- | Compute 'Declaration's for methods and functions in 'Syntax'. -syntaxDeclarationAlgebra :: HasField fields Range => Blob -> RAlgebra (TermF S.Syntax (Record fields)) (Term S.Syntax (Record fields)) (Maybe Declaration) +syntaxDeclarationAlgebra :: HasField fields Range => Blob -> RAlgebra (Term S.Syntax (Record fields)) (Maybe Declaration) syntaxDeclarationAlgebra blob@Blob{..} decl@(In a r) = case r of S.Function (identifier, _) _ _ -> Just $ FunctionDeclaration (getSource identifier) (getSyntaxDeclarationSource blob decl) blobLanguage S.Method _ (identifier, _) Nothing _ _ -> Just $ MethodDeclaration (getSource identifier) (getSyntaxDeclarationSource blob decl) blobLanguage Nothing diff --git a/src/Semantic/Task.hs b/src/Semantic/Task.hs index 132898282..e03d6e9ce 100644 --- a/src/Semantic/Task.hs +++ b/src/Semantic/Task.hs @@ -66,7 +66,7 @@ data TaskF output where WriteStat :: Stat -> TaskF () Time :: String -> [(String, String)] -> Task output -> TaskF output Parse :: Parser term -> Blob -> TaskF term - Decorate :: Functor f => RAlgebra (TermF f (Record fields)) (Term f (Record fields)) field -> Term f (Record fields) -> TaskF (Term f (Record (field ': fields))) + Decorate :: Functor f => RAlgebra (Term f (Record fields)) field -> Term f (Record fields) -> TaskF (Term f (Record (field ': fields))) Diff :: Differ syntax ann1 ann2 -> Term syntax ann1 -> Term syntax ann2 -> TaskF (Diff syntax ann1 ann2) Render :: Renderer input output -> input -> TaskF output Distribute :: Traversable t => t (Task output) -> TaskF (t output) @@ -116,7 +116,7 @@ parse :: Parser term -> Blob -> Task term parse parser blob = Parse parser blob `Then` return -- | A 'Task' which decorates a 'Term' with values computed using the supplied 'RAlgebra' function. -decorate :: Functor f => RAlgebra (TermF f (Record fields)) (Term f (Record fields)) field -> Term f (Record fields) -> Task (Term f (Record (field ': fields))) +decorate :: Functor f => RAlgebra (Term f (Record fields)) field -> Term f (Record fields) -> Task (Term f (Record (field ': fields))) decorate algebra term = Decorate algebra term `Then` return -- | A 'Task' which diffs a pair of terms using the supplied 'Differ' function.