"Apply" function of domain primitive types
valbers opened this issue · comments
Hi Scott,
First of all, thank you very much for all the material you provide to us! Your lessons are an invaluable help to any "mere mortal" interested in functional programming.
Regarding the sample code of this repository, I'm not sure if I found an inconsistency in the code or if I got something wrong and it would be great if you could clarify this question.
It's about the opaque types defined in DomainPrimitiveTypes.fsi
. Except for StringError
and IntegerError
, they all have an apply
function which reminds me of the apply
function as you define in your article https://fsharpforfunandprofit.com/posts/elevated-world/#apply . However, these apply
functions of the sample code are not really meant to be an incarnation of the apply
"metafunction" you define in your post, are they? I state this, because their signature doesn't match the expected signature of an apply
function as described by your post.
Take, for example, String10.apply
. It has this signature:
(string -> 'a) -> T -> 'a
In this code base, the elevated type is T
(which is defined to be of string
in the implementation code of String10
).
According to the definition of an apply
function in your aforementioned post, I'd have expected a signature that:
- Takes a function which is already in the elevated world (i.e. that would be
T<(string -> 'a)>
); - Returns a value which is also in the elevated world (i.e. that would be
T<'a>
).
So, why did you choose the name apply
for these concrete functions? Isn't it more like a Kleisli operation which assumes as the second parameter function the return
function for the elevated world of 'a
?
P.S.: what is the exact meaning of (String10 s)
in the signature of the implementation of val apply
? Is it a parameter named s
of type String10
? If so, does this syntax have the same effect of (s: String10)
?