18

Why can't I use optional parameters in loose functions defined with "let"?

Why are they only allowed in member functions?

Brian
  • 117,631
  • 17
  • 236
  • 300
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447

2 Answers2

22

I suspect they are provided only for compatibility with .NET functions. They aren't something you encounter in functional languages. The problem with an optional parameter is you can't curry it. If a function f's second parameter is optional, what is

let g = f x
?

Is it a function taking one argument, or a value obtained by evaluating f on x plus the default second parameter?

Drew Hoskins
  • 4,168
  • 20
  • 23
4

It is allowed in OCaml. Therefore it should be possible to implement it in F#.

http://caml.inria.fr/pub/docs/manual-ocaml/lablexamples.html#sec43

I guess it has been omitted for simplicity in F#.