caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Diego Olivier Fernandez Pons <Diego-Olivier.FERNANDEZ-PONS@cicrp.jussieu.fr>
To: Pierre Weis <pierre.weis@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Camlp4/OCaml [was: Generating C stubs]
Date: Tue, 21 May 2002 19:51:17 +0200 (DST)	[thread overview]
Message-ID: <Pine.A32.3.95.1020521191505.152434D-100000@ibm1.cicrp.jussieu.fr> (raw)
In-Reply-To: <200205180946.LAA26359@pauillac.inria.fr>

    Bonjour,

Je voulais seulement contribuer avec quelques exemples d'erreurs
auxquelles je me suis confronté et dont l'origine était une mauvaise
compréhension (de ma part) de la syntaxe de Caml.

la première concerne les séquences

val start : int
val coeff : int
val name : string option

method current_state = 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équence lie plus fortement que le séparateur d'éléments
dans une liste. Il suffit bien sûr - après avoir réfléchi un bon
moment - de mettre des parenthèses (mieux encore, d'évaluer le nom au
préalable et de concatener avec une constante ensuite)

A ce stade là on peste (quelques instants mais sans rancoeur réelle)
contre Caml pour avoir la mauvaise idée d'utiliser le point virgule
comme séparateur des listes plutôt que la très traditionnelle virgule.

Mais une autre erreur que j'ai commise plus d'une fois m'indique
immédiatement pourquoi c'est le cas :

[1, 2, 3] s'évalue en (int * int * int) list = [(1, 2, 3)]

car x, y est considérée comme une paire, d'où l'autre erreur qui m'a
perturbé pendant un certain temps

type term =
  | Constant of string * int
  | Variable of string
  | Apply of term * term list

let unify_terms env = function term1 term2 ->
  match (term1, term2) with
  | (Constant x, Constant y) -> (x = y, env)
  | (Variable x, Variable y) when x = 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ème de parenthèses, il faut s'habituer au fait
que x, y as value et (x, y) as value s'évaluent de la même façon.

        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


  reply	other threads:[~2002-05-23 20:51 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-15  9:13 [Caml-list] Generating C stubs Jérôme Marant
2002-05-15  9:49 ` Jocelyn Sérot
2002-05-15 12:17   ` Jérôme Marant
2002-05-15 12:38     ` Remi VANICAT
2002-05-15 20:19       ` Jérôme Marant
2002-05-16  7:06     ` Florian Hars
2002-05-16  7:34       ` Markus Mottl
2002-05-16 19:13         ` [Caml-list] Camlp4/OCaml [was: Generating C stubs] Daniel de Rauglaudre
2002-05-16 19:27           ` Chris Hecker
2002-05-16 19:39           ` John Prevost
2002-05-16 19:44             ` Daniel de Rauglaudre
2002-05-16 20:28               ` Chris Hecker
2002-05-16 21:38               ` Markus Mottl
2002-05-17  0:31                 ` Alessandro Baretta
2002-05-17 14:32                   ` Pierre Weis
2002-05-17 15:31                     ` Markus Mottl
2002-05-17 21:18                       ` Pierre Weis
2002-05-17 21:37                         ` Dave Mason
2002-05-18  9:46                           ` Pierre Weis
2002-05-21 17:51                             ` Diego Olivier Fernandez Pons [this message]
2002-05-19 11:31                         ` Markus Mottl
2002-05-21 17:10                           ` james woodyatt
2002-05-20  1:18                         ` [Caml-list] Tail recursion detection John Max Skaller
2002-05-21  7:46                           ` Alain Frisch
2002-05-21 11:35                             ` Benedikt Grundmann
2002-05-21 15:12                             ` John Max Skaller
2002-05-22 12:44                               ` Noel Welsh
2002-05-22 16:47                                 ` John Max Skaller
2002-05-21  8:57                           ` Noel Welsh
2002-05-20 22:59                     ` [Caml-list] Camlp4/OCaml [was: Generating C stubs] Alessandro Baretta
2002-05-16 23:22               ` [Caml-list] Re: Camlp4/OCaml Christopher Quinn
2002-05-17  7:02                 ` Daniel de Rauglaudre
     [not found]               ` <Pine.BSF.4.40.0205170357340.11758-100000@bpr.best.vwh.net>
2002-05-17  7:09                 ` [Caml-list] Camlp4/OCaml [was: Generating C stubs] Daniel de Rauglaudre
2002-05-17  7:54               ` [Caml-list] Camlp4/OCaml Michel Mauny
2002-05-17  8:05                 ` Daniel de Rauglaudre
2002-05-16 14:09 ` [Caml-list] Generating C stubs Benedikt Grundmann
2002-05-16 16:37 ` Jeff Henrikson
2002-05-16 16:31   ` Benedikt Grundmann
2002-05-17  5:59     ` Jeff Henrikson
2002-05-16 23:22 [Caml-list] Camlp4/OCaml [was: Generating C stubs] Joshua D. Guttman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.A32.3.95.1020521191505.152434D-100000@ibm1.cicrp.jussieu.fr \
    --to=diego-olivier.fernandez-pons@cicrp.jussieu.fr \
    --cc=caml-list@inria.fr \
    --cc=pierre.weis@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).