2 ms·
> "double kilometerToMiles(double km) { return km / 1.6 }" What about: toMiles (Kilometers k) = Miles (k/1.6) Then you do: let x = Kilometers 5 print
by marcosdumay 10y ago
> "double kilometerToMiles(double km) { return km / 1.6 }"
What about:
toMiles (Kilometers k) = Miles (k/1.6)
Then you do:
let x = Kilometers 5
print (toMiles x)
And, of course, any calculation will only accept the correct units. At this naive implementation, you'll have to add the conversions to satisfy the compiler, but there are Haskell libraries that bring automatic conversions too.
Anyway:
> Like types that are null or non-null, or tainted (from the user) or non-tainted.
That's Haskell.
> Or two numbers that are kilometers vs miles.
That's my example up there.
> Or only accessible under a certain lock or other preconditions.
Yep, Haskell.
> And be flow sensitive (kotlin style null checks), not make me write even more code.
That's emulating what people do in Haskell.