How to read F# type signatures?

后端 未结 4 868
死守一世寂寞
死守一世寂寞 2021-02-13 10:37

I\'m struggling with the F# type signature notation. For example let\'s say you have a Fold function:

let rec Fold combine acc l =
...

that may

4条回答
  •  无人共我
    2021-02-13 11:17

    You could write a similar function in F# which has a type like you're proposing (but in F# it would be written as ('a * 'b -> 'a) * 'a * list<'b> -> 'a. However, the advantage of the existing function is that it's easy to partially apply it by only supplying a prefix of the arguments. For instance:

    let sum = List.fold (+) 0
    

    Using your definition, you'd have to write

    let sum l = List.fold((fun (x,y) -> x + y), 0, l)
    

提交回复
热议问题