Skip to content

Instantly share code, notes, and snippets.

@cemerick
Last active April 13, 2018 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cemerick/bf64daf795823e0289c689af4386317c to your computer and use it in GitHub Desktop.
Save cemerick/bf64daf795823e0289c689af4386317c to your computer and use it in GitHub Desktop.
data Validity = Invalid | Valid deriving (Eq, Show, Generic, NFData)
data Readiness = NotReady | Ready deriving (Eq, Show, Generic, NFData)
asValid x = if x then Valid else Invalid
asReady x = if x then Ready else NotReady
data DFIO a = DFIO { valid :: Validity, ready :: Readiness, val :: a } deriving (Eq, Show, Generic, NFData)
dfio iV oR dat = DFIO (asValid iV) (asReady oR) dat
pending placeholder = DFIO Invalid NotReady placeholder
done result = DFIO Valid Ready result
isValid DFIO{..} = valid == Valid
isReady DFIO{..} = ready == Ready
mealyDF' :: HiddenClockReset dom gated sync
=> (s -> DFIO i -> (s, DFIO o))
-> s
-> DataFlow dom Bool Bool i o
mealyDF' f s = liftDF (\i iV oR -> let dfo = mealy f s $ dfio <$> iV <*> oR <*> i
in (fmap val dfo, fmap isValid dfo, fmap isReady dfo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment