-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix naming of initial and final algebras
- Loading branch information
Showing
16 changed files
with
187 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
|
||
module Data.Automaton.Recursive where | ||
|
||
-- base | ||
import Control.Applicative (Alternative) | ||
import Control.Arrow | ||
import Control.Category | ||
import Prelude hiding (id, (.)) | ||
|
||
-- transformers | ||
import Control.Monad.Trans.Reader | ||
|
||
-- automaton | ||
import Data.Automaton | ||
import Data.Stream.Optimized qualified as StreamOptimized | ||
import Data.Stream.Recursive qualified as StreamRecursive | ||
|
||
{- | Automata in direct recursive encoding. | ||
This type is isomorphic to @MSF@ from @dunai@. | ||
-} | ||
newtype Recursive m a b = Recursive {getRecursive :: StreamRecursive.Recursive (ReaderT a m) b} | ||
deriving newtype (Functor, Applicative, Alternative) | ||
|
||
instance (Monad m) => Category (Recursive m) where | ||
id = toRecursive id | ||
f1 . f2 = toRecursive $ fromRecursive f1 . fromRecursive f2 | ||
|
||
instance (Monad m) => Arrow (Recursive m) where | ||
arr = toRecursive . arr | ||
first = toRecursive . first . fromRecursive | ||
|
||
toRecursive :: (Functor m) => Automaton m a b -> Recursive m a b | ||
toRecursive (Automaton automaton) = Recursive $ StreamOptimized.toRecursive automaton | ||
|
||
fromRecursive :: Recursive m a b -> Automaton m a b | ||
fromRecursive Recursive {getRecursive} = Automaton $ StreamOptimized.fromRecursive getRecursive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.