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

Better interface for regEn #70

Closed tomjaguarpaw closed 8 years ago

tomjaguarpaw commented 8 years ago

regEn would be strictly typesafer if its signature were

regEn :: a -> Signal (Maybe a) -> Signal a

rather than

regEn :: a -> Signal Bool -> Signal a -> Signal a

This is very similar to https://github.com/clash-lang/clash-prelude/issues/42

tomjaguarpaw commented 8 years ago

I don't suggest to break this type signature but the new version could be added under a new name and the old one deprecated eventually.

tomjaguarpaw commented 8 years ago
regEnMaybe :: a -> Signal (Maybe a) -> Signal a
regEnMaybe = regEnMaybe' systemClock

regEnMaybe' :: SClock clk -> a -> Signal' clk (Maybe a) -> Signal' clk a
regEnMaybe' clk initial input = regEn' clk initial (fmap isJust input)
                                  $ fmap fromJust input
christiaanb commented 8 years ago

I prefer the name regMaybe, thoughts?

tomjaguarpaw commented 8 years ago

regMaybe seems good.

tomjaguarpaw commented 8 years ago

In fact registerMaybe is even better.