You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As covered in various conversations, a lot about Digit:-
[<Struct>]
type Digit =
val value: int
new(value) =
if value < 0 || value > 9 then
invalidArg "value" "A digit value should be from 0 to 9"
{ value = value }
override this.ToString() = string this.value
bothers me:-
having 8 lines (out of 37) in the UL (and if it was a single line in some cases it can sit beside another single line def allowing us to convey relatedness so really it's 9)
using attributes (esp in UL)
having code in the UL
Because its a struct, you can still Digit () to bypass the ctor [which is OK in this case as 0 happens to be valid]
The digit vs Digit clashes it causes are a mess
The following lipstick makes it a bit nicer:
let inline between min max value =
if value >= min && value <= max then
sprintf "A digit value should be between %A and %A" min max
|> invalidArg "value"
value
type Digit = struct
val value:int
new value = { value = value |> between 0 9 }
override this.ToString() = string this.value end
If you felt strongly about perf requirements enough to prematurely optimize (or a profiler proof said do it, I think I'd probably make it the following one liner:
type Digit = struct val value:int; new value = { value = value |> between 0 9 } end
(I'd remove the reliance on ToString() (there's still %A and your Json converters)
I'd still be annoyed to have to place the between helper somewhere (though in practice there's always an Operators.fs in any 'real' project :D (And then to have to fight about a better name)
Final conclusion: I'd prefer
type Digit = Digit of int
thoughts ?
The text was updated successfully, but these errors were encountered:
As covered in various conversations, a lot about
Digit
:-bothers me:-
struct
, you can stillDigit
() to bypass the ctor [which is OK in this case as0
happens to be valid]digit
vsDigit
clashes it causes are a messThe following lipstick makes it a bit nicer:
If you felt strongly about perf requirements enough to prematurely optimize (or a profiler proof said do it, I think I'd probably make it the following one liner:
(I'd remove the reliance on
ToString()
(there's still%A
and your Json converters)I'd still be annoyed to have to place the
between
helper somewhere (though in practice there's always anOperators.fs
in any 'real' project :D (And then to have to fight about a better name)Final conclusion: I'd prefer
thoughts ?
The text was updated successfully, but these errors were encountered: