Re: 'a versus ('a)
"Gabriel Scherer [email protected] [ocaml_beginners]" <[email protected]> Mon, 30 May 2016 14:51:40 -0400
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAPFanBE8=w87QO=b7p6Rh4TDdSODaTz1FSyg0z4cSDd-Sf5NZg@mail.gmail.com> |
If you have several type parameters you need to write ('a, 'b, 'c) for
example. For a single parameter, both are perfectly equivalent, so you
can use the one you like best. I think just 'a is more common; I don't
remember seeing ('a) in the wild, although it could make sense for
consistency or if in a temporary state if you had two parameters and
are currently editing the code to try it with only one.
You can also not give a name to the parameter by using _ in this
position. This is sometimes used with some advanced features/patterns:
when defining a phantom type (where the parameter is not used at all),
or when using a GADT (where the parameter value will be set by each
constructor separately).
On Mon, May 30, 2016 at 2:32 PM, Manfred Lotz [email protected]
[ocaml_beginners] <[email protected]> wrote:
> I have seen both 'a and ('a) in type definitions like this:
>
> type 'a tree = Leaf of 'a | Node of 'a tree * 'a tree;;
>
> type ('a) tree = Leaf of 'a | Node of 'a tree * 'a tree;;
>
> It seems they are equivalent.
>
> Is there a reason why I would write ('a) instead of just 'a? Or is is
> just a matter of taste?
>
> --
> Manfred
>
>
>
>
> ------------------------------------
> Posted by: Manfred Lotz <[email protected]>
> ------------------------------------
>
> Archives up to December 31, 2011 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners
> The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames etc.
> ------------------------------------
>
> Yahoo Groups Links
>
>
>