clash-lang / clash-prelude

CLaSH prelude library containing datatypes and functions for circuit design
http://www.clash-lang.org/
Other
31 stars 27 forks source link

Pipelines? #83

Open ggreif opened 7 years ago

ggreif commented 7 years ago

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.

ra1u commented 7 years ago

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