Use DriveVoid typeclass instead of Default for underscored circuits#25
Use DriveVoid typeclass instead of Default for underscored circuits#25t-wallet wants to merge 2 commits intocchalmers:masterfrom
Conversation
src/Circuit.hs
Outdated
| instance (Void a) => Void (Signal dom a) where | ||
| driveVoid = pure driveVoid | ||
|
|
||
| instance Void (DFM2S a) where |
There was a problem hiding this comment.
Do we need this? I can see in the code addDef could be used for a Forward, But when does this happen?
There was a problem hiding this comment.
The examples do not only contain function like this:
fstC2 :: Circuit (Signal domain a, Signal domain b) (Signal domain a)
fstC2 = circuit $ \ab -> do
(a, _b) <- idC -< ab
idC -< aBut also functions like this:
unfstC3 :: Circuit (DF dom a) (DF dom a, DF dom b)
unfstC3 = circuit $ \a -> do
ab <- idC -< (a, _b)
ab' <- idC -< ab
idC -< ab'So you can easily create an empty stream if you need it.
|
|
|
|
After thinking about this for a little bit: it seems to me that this abstraction isn't quite right. We'll end up with situations where multiple protocols use the same type (e.g., class DriveVoid a where
driveVoidFwd :: Fwd a
driveVoidBwd :: Bwd aHowever, this means type family Fwd a
type family Bwd a
-- vs
class Protocol a where
type Fwd (a :: Type)
type Bwd (a :: Type)and newtype Circuit a b = Circuit { runCircuit :: CircuitT a b }
type CircuitT a b = (Fwd a :-> Bwd b) -> (Bwd a :-> Fwd b)
-- vs
newtype Circuit a b = Circuit ((Fwd a, Bwd b) -> (Bwd a, Fwd b)) |
|
If we rewrite it to: class DriveVoid a where
driveVoidFwd :: Fwd a
driveVoidBwd :: Bwd aWe might want to consider adding a possibility to stall the pipeline: class DriveVoid a where
driveVoidFwd :: Fwd a
driveVoidBwd :: Bwd a
driveVoidBwdNack :: Bwd a -- needs better name?Then we could drop the |
See clash-lang/clash-protocols#92. Feel free to suggest different different names for the typeclass/functions.