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 RAA30213; Sat, 7 Sep 2002 17:52:50 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 RAA30133 for ; Sat, 7 Sep 2002 17:52:49 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g87Fqm106653 for ; Sat, 7 Sep 2002 17:52:48 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id RAA19421 for caml-list@inria.fr; Sat, 7 Sep 2002 17:52:48 +0200 Date: Sat, 7 Sep 2002 17:52:48 +0200 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] Camlp4-tutorial-Example Message-ID: <20020907175248.B18830@verdot.inria.fr> References: <20020903090842.B30173@verdot.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from oliver@first.in-berlin.de on Sat, Sep 07, 2002 at 01:10:53AM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Sat, Sep 07, 2002 at 01:10:53AM +0200, Oliver Bandel wrote: > Yes, i've seen that it is possible to get back functions > that, if applied, will give the resulting int. > But a) it's again int and b) all functions have same type. > What if I need a function that returns back a string? No problem. A grammar entry, like a function, can return any type. But if you want that the arithmetic calculator of the example in the Camlp4 tutorial can return any type, in this case, it is not a problem of the Camlp4 grammar, but a problem of typing in OCaml. How would you make a function returning values of several possible types? Indeed with the type like you say: > type myresult = Int of int | String of string > P.S.: I looked at the example with List.assoc on page 11 and 12. > I think that's a way to implement own variables of a simple > language. Very easy, and again surprising. > (Here again: how to use string-variables in a language > to implement?) In this case, the "env" list of the example must be of type: (string * myresult) list ref And yo must enter the variable "foo" by: env := ("foo", Int 27) :: env -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- 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