3 ms·
There's one thing I don't understand in the following signature provided for bind : val bind : ('a -> Result<'b,'c>) -> Result<'a,'c> -> Result<'b,'c> The a
by pyrale 10y ago
There's one thing I don't understand in the following signature provided for bind :
val bind : ('a -> Result<'b,'c>) -> Result<'a,'c> -> Result<'b,'c>
The author says that it takes one parameter, a function and returns another function, but then why are there 3 args in the signature ?
I would have expected something like this :
val bind : ('a -> Result<'b,'c>) -> (Result<'a,'c> -> Result<'b,'c>)
for something that takes a function and returns another function adapted to the input, or something like this :
val bind : ('a -> Result<'b,'c>) -> Result<'a,'c> -> Result<'b,'c>
for a function that takes a function G and an input I and applies G to I if possible ad returns the eventual result (curried, Haskell-style).
What am I missing about F# ?
- elros 10y agoI don't know much about F#, but in a language with currying, such distinction does not exist, given f(x, y) == f(x)(y)
- pyrale 10y agoMy puzzlement came from the fact that : f(in -> out)(in') -> out == f((in -> out), in') -> out and f(in -> out) -> (in' -> out) are similar. But thinking some more about it, I don't see a good reason for which this would be a problem. This simply means that any function defined to take [] elements is also able to take [:x] and return a function taking [x:]... I hadn't thought about this particular thing until now, but this kind of halfway-through computation is interesting.
- grndn 10y agoYou are on the right track (no pun intended). Your second and third function signatures are actually the same thing in F# (and any other language with curried functions by default). Similar functions such as "map" and "filter" can be thought of the same way. A big benefit of currying by default is that all functions can be treated as one parameter functions -- a very powerful tool for function composition. Also, providing only some of the parameters (e.g. the first) and leaving some to be provided later is the technique known as "partial application" -- another key tool in functional programming. If you think these things look interesting, you should for sure look into F#/OCaml/Haskell/Elm/etc.