From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id C872FBC57 for ; Wed, 15 Dec 2010 18:13:17 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuUAACeGCE3RVdi0imdsb2JhbACVTIYyAYgjCBUBAQEKCQwHDwYgqQSJcIIYhS8uiFcBAQMFhUUEgWCDP4VchgiDLw X-IronPort-AV: E=Sophos;i="4.59,350,1288566000"; d="scan'208";a="70733799" Received: from mail-qy0-f180.google.com ([209.85.216.180]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-MD5; 15 Dec 2010 18:13:07 +0100 Received: by qyk29 with SMTP id 29so2167985qyk.18 for ; Wed, 15 Dec 2010 09:13:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=7DjV3+JsOBzsyodU4KdNCQhXUM+LH+Js8P0Sq26eSiQ=; b=PDy0GkRv8fthOg4G+EfD+7KhZ0vd1CQesOO4Sy7HZCOMyFfNa3pR8jLdqMzqynfbk/ /fHa5ZnxUtEsalq3n65R2Zbh4LqeM0wHiWbSTIfDH4DBpwUARDmvqmRnNtp3fHr2om6X Fw8Lncpu1ILS2xfDVuCEt/3j/W/Xypa7p1VTc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=b6srdDPdlTF+3yQ+Ybk3gL0HXHZncESbisDVfuD+5wQAO1PpwE8Rk2cQ5YxZ4a2vZt QSxvUJ/sWdCcYVrQ8I2oPVCKeXyEyi4k0GZ63nNuGGKVWnNi+yloH9ZWvg02rkBSroqP MI/Y8P+XhSFvAlGHK3GQfhzfMQ4gkdfqK/Hi4= Received: by 10.229.251.139 with SMTP id ms11mr700635qcb.198.1292433183286; Wed, 15 Dec 2010 09:13:03 -0800 (PST) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.229.23.139 with HTTP; Wed, 15 Dec 2010 09:12:43 -0800 (PST) In-Reply-To: <201012151756.48546.raphlalou@gmail.com> References: <30464033.post@talk.nabble.com> <30465308.post@talk.nabble.com> <201012151756.48546.raphlalou@gmail.com> From: bluestorm Date: Wed, 15 Dec 2010 18:12:43 +0100 X-Google-Sender-Auth: d0Q2gX4kguzI5uxwEBmZv_i8KQc Message-ID: Subject: Re: [Caml-list] Doubt about function delaration parameter To: raphlalou@gmail.com Cc: caml-list@yquem.inria.fr, sieira Content-Type: multipart/alternative; boundary=00163631020dc925c90497760c8d X-Spam: no; 0.00; foo:01 baz:01 foo:01 ocaml:01 ocaml:01 checker:01 abbreviation:01 semantics:01 syntax:01 node:01 haskell:01 beginner's:01 bug:01 baz:01 checker:01 --00163631020dc925c90497760c8d Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable In Caml Light, the rule is the following : - if you declare a *new* type, such as a sum type ( Foo | Bar | Baz ) or a record type ( { foo : t; bar : t' } ), use "=3D" - if you just add an alias, a new name for an existing type, use "=3D=3D" It is an alias if the right-hand side is a "type expression" (something you could use as is in a type annotation) It is interesting to note that, though less syntactically visible, the difference has not vanished in OCaml. OCaml type declarations may have two components, a type "equation" (~ alias for a type expression) and a "representation" (~ new ADT). For example the following is valid : type test =3D A.ty =3D A | B | C The type is declared to be an alias to the type "ty" in the module A, and also represented by the sum (A | B | C) : the definition is "re-exported", and an error will be thrown if A.ty is different from (A | B | C). It is occasionnaly nice to make representation explicit, while still keeping compatibility at the type level (the two types are considered equal by the type checker), and can also be avoid to "strenghten" an external dependency : if the upstream type definition changes, I'm sure my code will fail here instead of producing weird errors later. See the OCaml manual : http://caml.inria.fr/pub/docs/manual-ocaml/manual016.html The difference between type declarations and alias/abbreviation is also significant for the semantics of "private types", which are an extension (o= r rather several successive extensions) to the OCaml language described here : http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc76 . On Wed, Dec 15, 2010 at 5:56 PM, Raphael Proust wrote= : > Le mercredi 15 d=E9cembre 2010 17:15:23, sieira a =E9crit : > > Thanks for your replies. I'm now having some issue with Raphael's > > suggestion of using (string * string) list;; as the menu type. > > > > > > type menu =3D (string*string) list;; > > > > Results in a syntax error at the first parenthesis, while > > > > type menu =3D string*string;; > > > > fails too (at the asterisk) > > > > It seems like I'm missing something. Since according to the > > http://caml.inria.fr/pub/docs/manual-caml-light/node3.5.html > documentantion > > , this sintax should be right. > > > > I'm using Camllight 0.81 by Fran=E7ois Boisson running in Ubuntu lucid = lynx > > I just installed Camllight and I encountered the problem as you. Because > the > type menu is just a shorter name for the complete type (string * string) > list, > you have to use: > type menu =3D=3D ( string * string ) list ;; > > (with two '=3D' signs) > I don't know the exact rule about this. It might be close to the differen= ce > between 'type' and 'data' in Haskell. > > Good luck! > -- > _______ > Rapha=EBl > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --00163631020dc925c90497760c8d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
In Caml Light, the rule is the following :
- if you declare a *new* = type, such as a sum type ( Foo | Bar | Baz ) or a record type ( { foo : t; = bar : t' } ), use "=3D"
- if you just add an alias, a new name for an existing type, use "= ;=3D=3D"

It is an alias if the right-hand sid= e is a "type expression" (something you could use as is in a type= annotation)

It is interesting to note that, though less synta= ctically visible, the difference has not vanished in OCaml.
OCaml= type declarations may have two components, a type "equation" (~ = alias for a type expression) and a "representation" (~ new ADT). = For example the following is valid :

=A0=A0type test =3D A.ty =3D A | B | C

The type is declared to be an alias to the type "ty" in = the module A, and also represented by the sum (A | B | C) : the definition = is "re-exported", and an error will be thrown if A.ty is differen= t from (A | B | C). It is occasionnaly nice to make representation explicit= , while still keeping compatibility at the type level (the two types are co= nsidered equal by the type checker), and can also be avoid to "strengh= ten" an external dependency : if the upstream type definition changes,= I'm sure my code will fail here instead of producing weird errors late= r.

The difference between type declaratio= ns and alias/abbreviation is also significant for the semantics of "pr= ivate types", which are an extension (or rather several successive ext= ensions) to the OCaml language described here :=A0http://caml.inria.fr/pub= /docs/manual-ocaml/manual021.html#toc76=A0.



On Wed, D= ec 15, 2010 at 5:56 PM, Raphael Proust=A0<raphlalou@gmail.com>=A0wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin-top: 0px; margin-right: 0p= x; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-l= eft-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;= "> Le mercredi 15 d=E9cembre 2010 17:15:23, sieira a =E9crit :
> Thanks for your replies. I'm now having some issue with Ra= phael's
> suggestion of using (string * string) list;; as the men= u type.
>
>
> type menu =3D (string*string) list;;
>
> R= esults in a syntax error at the first parenthesis, while
>
> ty= pe menu =3D string*string;;
>
> fails too (at the asterisk)
>
> It seems like I'm missing something. Since according to th= e
>=A0http://caml.inria.fr/pub/docs/manual-caml-light= /node3.5.html=A0documentantion
> , this sintax should be right.
>
> I'm using Camllight= 0.81 by Fran=E7ois Boisson running in Ubuntu lucid lynx

I jus= t installed Camllight and I encountered the problem as you. Because the
type menu is just a shorter name for the complete type (string * string) li= st,
you have to use:
type menu =3D=3D ( string * st= ring ) list ;;

(with two '=3D' signs)
I don't k= now the exact rule about this. It might be close to the difference
between 'type' and 'data' in Haskell.

Good luck!
= --
_______
Rapha=EBl

_______________________________________________
= Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-listArchives:=A0http://cam= l.inria.fr
Beginner's list:=A0http://groups.yahoo.com/group/ocaml_beginnersBug reports:=A0http://caml.inria.fr/bin/caml-bugs

--00163631020dc925c90497760c8d--