←back to thread

611 points LorenDB | 3 comments | | HN request time: 0.614s | source
Show context
adamc ◴[] No.43908291[source]
Coming from python (or Common Lisp, or...), I wasn't too impressed. In Python I normally make args for any function with more than a couple be keyword arguments, which guarantees that you are aware of how the arguments are being mapped to inputs.

Even Rust's types aren't going to help you if two arguments simply have the same types.

replies(1): >>43908499 #
rq1 ◴[] No.43908499[source]
Just create dummy wrappers to make a type level distinction. A Height and a a Width can be two separate types even if they’re only floats basically.

Or another (dummy) example transfer(accountA, accountB). Make two types that wrap the same type but one being a TargetAccount and the other SourceAccount.

Use the type system to help you, don’t fight it.

replies(1): >>43908843 #
jpc0 ◴[] No.43908843[source]
Do you really want width and height or do you actually want dimensions or size? Same with transfer, maybe you wanted a transaction that gets executed. Worst case here use a builder with explicit function names.
replies(1): >>43909500 #
1. rq1 ◴[] No.43909500[source]
I don’t really understand your point there.

Sound type systems are equivalent to proof systems.

You can use them to design data structures where their mere eventual existence guarantee the coherence and validity of your program’s state.

The basic example is “Fin n” that carries at compile time the proof that you made the necessary bounds checks at runtime or by construction that you never exceeded some bound.

Some languages allow you to build entire type level state machines! (eg. to represent these transactions and transitions)

replies(1): >>43911490 #
2. jpc0 ◴[] No.43911490[source]
My point is a Width type is usually not the sound type you are looking for. What probably wanted was a size type which is width and height. Or a dimensions type which is width and height. The problem was maybe not two arguments being confused but in reality a single thing with two elements…
replies(1): >>43913834 #
3. rq1 ◴[] No.43913834[source]
Ah I see, it’s a solution too!