caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Camlp4-tutorial-Example
Date: Sat, 7 Sep 2002 17:52:48 +0200	[thread overview]
Message-ID: <20020907175248.B18830@verdot.inria.fr> (raw)
In-Reply-To: <Pine.LNX.3.95.1020907005853.312A-100000@first.in-berlin.de>; from oliver@first.in-berlin.de on Sat, Sep 07, 2002 at 01:10:53AM +0200

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


      reply	other threads:[~2002-09-07 15:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-02 19:52 Oliver Bandel
2002-09-02 20:52 ` Oliver Bandel
2002-09-02 21:43   ` Oliver Bandel
2002-09-03  7:08   ` Daniel de Rauglaudre
2002-09-04 19:46     ` Oliver Bandel
2002-09-06 23:10     ` Oliver Bandel
2002-09-07 15:52       ` Daniel de Rauglaudre [this message]

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=20020907175248.B18830@verdot.inria.fr \
    --to=daniel.de_rauglaudre@inria.fr \
    --cc=caml-list@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).