Created
October 10, 2012 09:43
-
-
Save YoEight/3864415 to your computer and use it in GitHub Desktop.
Haskell machine package examples
This file contains hidden or 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
module Examples where | |
import Control.Applicative | |
import Control.Monad.Trans | |
import Data.Machine | |
data Bit = EMPTY | One | Zero | |
instance Show Bit where | |
show One = "1" | |
show Zero = "0" | |
show _ = "" | |
-- Binary adding machine | |
adding :: Moore Bit Bit | |
adding = Moore EMPTY carried | |
where | |
absorbed One = Moore One absorbed | |
absorbed Zero = Moore Zero absorbed | |
carried One = Moore Zero carried | |
carried Zero = Moore One absorbed | |
printer :: (MonadIO m, Show a) => ProcessT m a () | |
printer = repeatedly $ liftIO . print =<< await | |
little_endian = reverse | |
test = printer <~ auto adding <~ source (little_endian [Zero, One, Zero, One]) -- prints [0,1,1,0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment