What is a term in the context of cmdliner?

Viewed 56

Cmdliner is an awesome tool to build command line applications in OCaml. However, the entire documentation is explained around the word “term”. This makes it hard for me to understand the docs properly because I’m constantly thinking about what term refers to. Because how generic and broad the term "term" is it's very hard to google it, so any explanation in context will be awesome. Even in the specific page of the term I could not find any specific explanation of what a term is

1 Answers

I looked through the page to which you linked. Here's a quick summary: a term is a value of type 'a Cmdliner.Term.t. Because of the 'a type variable, this can be a value of any type at all. It's a value essentially wrapped up in a container provided by Cmdliner.Term.

To work with terms you have two functions: const and app. const wraps up any value of type 'a into a term. Note that the wrapped value can be a function (as functions are values). app applies a wrapped function to a wrapped value and gives you back the result as a wrapped value.

The reason this is difficult to follow is that it really is completely abstract. You can use any type you like for 'a (as long as you use it consistently), and you can apply any functions you like to such values (again as long as the types are correct).

I hope this helps. Someone with more (or any :-) experience with Cmdliner can probably be more helpful.

Related