News for hackers. Stuff that matters.
Re:Railway oriented programming by pyrale on Thursday June 23, 2016 @09:27AM (#11960672)
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# ?

Re:Railway oriented programming by elros on Thursday June 23, 2016 @09:29AM (#11960694)
I don't know much about F#, but in a language with currying, such distinction does not exist, given f(x, y) == f(x)(y)
Re:Railway oriented programming by pyrale on Thursday June 23, 2016 @10:15AM (#11960978)
My 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.

Re:Railway oriented programming by grndn on Thursday June 23, 2016 @12:56PM (#11962492)
You 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.