From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA12024; Thu, 23 May 2002 22:51:55 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA12037 for caml-list@pauillac.inria.fr; Thu, 23 May 2002 22:51:54 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA23844 for ; Tue, 21 May 2002 19:53:28 +0200 (MET DST) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g4LHrOX19969; Tue, 21 May 2002 19:53:28 +0200 (MET DST) Received: from ibm3.cicrp.jussieu.fr (ibm3.cicrp.jussieu.fr [134.157.15.3]) by shiva.jussieu.fr (8.12.3/jtpda-5.4) with ESMTP id g4LHrO5R026881 ; Tue, 21 May 2002 19:53:24 +0200 (CEST) Received: from ibm1.cicrp.jussieu.fr (ibm1.cicrp.jussieu.fr [134.157.15.1]) by ibm3.cicrp.jussieu.fr (8.8.8/jtpda/mob-V8) with ESMTP id TAA30030 ; Tue, 21 May 2002 19:51:17 +0200 Received: from localhost (fernande@localhost) by ibm1.cicrp.jussieu.fr (8.8.8/jtpda/mob-v8) with SMTP id TAA151884 ; Tue, 21 May 2002 19:51:17 +0200 Date: Tue, 21 May 2002 19:51:17 +0200 (DST) From: Diego Olivier Fernandez Pons To: Pierre Weis cc: caml-list@inria.fr Subject: Re: [Caml-list] Camlp4/OCaml [was: Generating C stubs] In-Reply-To: <200205180946.LAA26359@pauillac.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Bonjour, Je voulais seulement contribuer avec quelques exemples d'erreurs auxquelles je me suis confront=E9 et dont l'origine =E9tait une mauvaise compr=E9hension (de ma part) de la syntaxe de Caml. la premi=E8re concerne les s=E9quences val start : int val coeff : int val name : string option method current_state =3D function () -> ["name : " ^ match name with None -> "unknown name" | Some n -> n ; "coeff : " ^ string_of_int coeff ; "start : " ^ string_of_int start ] ce qui donne lorsqu'on compile Warning: this expression should have type unit method current_state : unit -> string list En effet, la s=E9quence lie plus fortement que le s=E9parateur d'=E9l=E9men= ts dans une liste. Il suffit bien s=FBr - apr=E8s avoir r=E9fl=E9chi un bon moment - de mettre des parenth=E8ses (mieux encore, d'=E9valuer le nom au pr=E9alable et de concatener avec une constante ensuite) A ce stade l=E0 on peste (quelques instants mais sans rancoeur r=E9elle) contre Caml pour avoir la mauvaise id=E9e d'utiliser le point virgule comme s=E9parateur des listes plut=F4t que la tr=E8s traditionnelle virgule= =2E Mais une autre erreur que j'ai commise plus d'une fois m'indique imm=E9diatement pourquoi c'est le cas : [1, 2, 3] s'=E9value en (int * int * int) list =3D [(1, 2, 3)] car x, y est consid=E9r=E9e comme une paire, d'o=F9 l'autre erreur qui m'a perturb=E9 pendant un certain temps type term =3D | Constant of string * int | Variable of string | Apply of term * term list let unify_terms env =3D function term1 term2 -> match (term1, term2) with | (Constant x, Constant y) -> (x =3D y, env) | (Variable x, Variable y) when x =3D y -> (true, env) | (Variable x, Variable y) -> (true, (x, Variable y) :: env) | (const, Variable _ as var) -> unify_terms env var const etc. This expression has type term * term but is here used with type term C'est encore un probl=E8me de parenth=E8ses, il faut s'habituer au fait que x, y as value et (x, y) as value s'=E9valuent de la m=EAme fa=E7on. Diego Olivier ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners