9 ms·
tl;dr: use newtypes! I like using static types to avoid these sorts of problems. Modern languages like Swift, Rust and Haskell let you make zero-overhead type
by pshc 10y ago
tl;dr: use newtypes!
I like using static types to avoid these sorts of problems. Modern languages like Swift, Rust and Haskell let you make zero-overhead type wrappers around other types.
So here they could have defined `newtype RisingEdge(Float)` and `newtype FallingEdge(Float)`, and then use those types in the function parameters as appropriate.
Helps shorten function names to boot!
- saosebastiao 10y agoThis is incredibly powerful when done correctly. Ive come across a few similar features in F# that I wish were available in other languages, such as units of measure (F#) and active patterns.
- Roboprog 10y agoI miss Pascal "type" block definitions (or C typedefs, at least) when I have to work with too many Java generics. I know, [Turbo] Pascal (etc) never had generics. But if they had, you would have been able to make a type with a generic expression, rather than a constantly repeated inline monstrosity of an expression.