by pyrale · 10y ago · 0 comments
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# ?
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.
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.