On Thu, Jan 18, 2024 at 03:28:39PM +0100, Laszlo Ersek wrote:
On 1/17/24 14:24, Richard W.M. Jones wrote:
On Wed, Jan 17, 2024 at 07:17:39AM +0100, Laszlo Ersek wrote:
On 1/15/24 19:24, Richard W.M. Jones wrote:
-let download_file uri output = +let download_file ~password ?port ~server ?user path output =
(1) so here's where I suggest that (if syntactically possible) we don't bind "password", just use "_".
Since the parameter is labelled you can't replace the parameter with '_', since that means the function type changes.
However (I discovered today) you can use ~password:_ which doesn't bind password inside the function:
# let f ~password a = a ;; val f : password:'a -> 'b -> 'b = <fun> # let f _ a = a ;; val f : 'a -> 'b -> 'b = <fun> # let f ~password a = password ;; val f : password:'a -> 'b -> 'a = <fun> # let f ~password:_ a = password ;; Error: Unbound value password
So I used ~password:_ in the updated patch.
Very cool!
I find OCaml relatively non-intuitive when it comes to taking parameters (well, because there are only single-arg functions in ocaml, I should say "when it comes to taking the parameter"), but I can't deny the syntax does seem to cover everything imaginable.
Yes I think you just have to memorize all the combinations. The labelled / optional arg feature is quite powerful, more so than Python at least. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org