Skip to content

Instantly share code, notes, and snippets.

@YoEight
Created October 10, 2012 09:43
Show Gist options
  • Save YoEight/3864415 to your computer and use it in GitHub Desktop.
Save YoEight/3864415 to your computer and use it in GitHub Desktop.
Haskell machine package examples
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