Advertisement
Guest User

labelled arguments and applicative functor

a guest
Dec 14th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.77 KB | None | 0 0
  1. (* How do I use a function with labeled arguments in an
  2.  * applicative functor setting? *)
  3. let chorus ~count ~msgs =
  4.   Printf.printf "chorus %d %s\n" count msgs
  5.  
  6.  
  7. (* The obvious solution is to convert my labelled arguments
  8.  * to positional arguments when passing my function to cmdliner *)
  9. let chorus_t1 = Term.(
  10.   pure (fun count msgs -> chorus ~count ~msgs) $
  11.   count $ msgs)
  12.  
  13. (* This other way I found lets you specify the arguments one at a time
  14.  * using partial application... but it looks awful!
  15.  * And the order is still fixed - it doesn't compile if you put the
  16.  * "count" line after the "msgs" line *)
  17. let ($!) a b = Term.($) b a
  18. let chorus_t2 = Term.(
  19.   pure chorus $!
  20.   (count $! pure (fun x f -> f ~count:x)) $!
  21.   (msgs $! pure (fun x f -> f ~msgs:x))
  22. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement