clash-prelude
clash-prelude copied to clipboard
Pipelines?
I have just written a toy 3-stage pipeline for a moore
machine:
pip3 :: (a -> b) -> (b -> c) -> (c -> d) -> (b, c, d) -> a -> (b, c, d)
pip3 f g h (b, c, _) a = (f a, g b, h c)
pmoore = moore (pip3 (*2) show read) project3 (0, "42", 1)
where project3 (b, c, d) = d
I wonder whether such a thing would be useful for folks. If not, please close. Otherwise I could come up with a pull request. Of course many variants (types of feedback/mealy
etc.) would be possible, so some guidance is welcome.
I like idea if it can be extended to generic approach that enables support for wide range of use-cases. I am not sure what function did you aim for, but for pmoore
there is also alternative approach that can be useful.
pmoore = r 1 read . r "42" show . r 0 (*2)
where
r a f = register a . fmap f