Re: 'a versus ('a)

"Manfred Lotz [email protected] [ocaml_beginners]" <[email protected]> Tue, 31 May 2016 11:43:58 +0200
Newsgroups gmane.comp.lang.ocaml.beginners
Message-ID <[email protected]>
On Mon, 30 May 2016 17:28:32 -0400
"Gabriel Scherer [email protected] [ocaml_beginners]"
<[email protected]> wrote:

> (* phantom type:
> http://camltastic.blogspot.com/2008/05/phantom-types.html *) type _
> foo = Foo
> 
> (* GADT:
> http://caml.inria.fr/pub/docs/manual-ocaml-4.03/extn.html#sec238 *)
> type _ tag = | TInt : int tag
>   | TFloat : float tag
> 

Great, thanks a lot for the pointers.



> On Mon, May 30, 2016 at 4:54 PM, Manfred Lotz [email protected]
> [ocaml_beginners] <[email protected]> wrote:
> > Thanks for your answer.
> >
> > On Mon, 30 May 2016 14:51:40 -0400
> > "Gabriel Scherer [email protected] [ocaml_beginners]"
> > <[email protected]> wrote:
> >  
> >> If you have several type parameters you need to write ('a, 'b, 'c)
> >> for example.  
> >
> > Yes.
> >  
> >> 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. 
> >
> > Good. For me 'a without parenthesis looks more natural.
> >  
> >> 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).
> >>  
> >
> > Hm, I have to admit that in order to understand this better I would
> > need an example.
> >
> >  
> >> 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
> >> >
> >> >
> >> >  
> >
> >
> >
> > ------------------------------------
> > 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
> >
> >
> >