Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

DataFlow: Introduce liftDF' #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Clash/Prelude/DataFlow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module Clash.Prelude.DataFlow
DataFlow (..)
-- * Creating DataFlow circuits
, liftDF
, liftDF'
, Ready(..)
, pureDF
, mealyDF
, mooreDF
Expand Down Expand Up @@ -140,6 +142,25 @@ liftDF :: (Signal dom i -> Signal dom Bool -> Signal dom Bool
-> DataFlow dom Bool Bool i o
liftDF = DF

-- | A readiness value.
data Ready a = Ready | NotReady
deriving (Eq, Ord, Show)

-- | Like 'liftDF' but with slightly more descriptive types.
liftDF' :: (Signal dom (Maybe i) -> Signal dom (Ready o)
-> (Signal dom (Maybe o), Signal dom (Ready i)))
-> DataFlow dom Bool Bool i o
liftDF' f = DF $ \iData iValid oReady ->
let validToMaybe valid dat
| valid = Just dat
| otherwise = Nothing
boolToReady b = if b then Ready else NotReady
(o, iReady) = f (validToMaybe <$> iValid <*> iData)
(fmap boolToReady oReady)
oValid = isJust <$> o
oData = maybe (error "liftDF': dummy data") id <$> o
in (oData, oValid, (== Ready) <$> iReady)

-- | Create a 'DataFlow' circuit where the given function @f@ operates on the
-- data, and the synchronisation channels are passed unaltered.
pureDF :: (i -> o)
Expand Down