caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: dmcclain@azstarnet.com (David McClain)
Cc: caml-list@inria.fr (OCAML)
Subject: Re: Dichotomy between functions and type constructors?
Date: Mon, 21 Feb 2000 20:31:07 +0100 (MET)	[thread overview]
Message-ID: <200002211931.UAA03460@miss.wu-wien.ac.at> (raw)
In-Reply-To: <000501bf7a51$60490100$250148bf@vega> from "David McClain" at Feb 18, 2000 01:47:28 PM

> Say I have a type
> 
>    T1 of int * float

> I can create such a type as T1(5, 3.14) but I cannot create such a type on a
> tuple result of a function call:
> 
> let doit x = (x, float_of_int x)
> 
> let myT1 = T1(doit x)

This is a trap into which I have already fallen when I tried to find a bug
in a C-interface. Xavier explained the "problem" to me when I sent a bug
report, because I had thought that the source of the error originated in
OCaml:

  type t = T1 of int * float

is *not* the same as:

  type t = T1 of (int * float)

The first one is an example of a dataconstructor that takes two arguments
(an int and a float), whereas the second one is a dataconstructor that
takes *one* argument which happens to be a tuple...

So this, for example, works:

  type t = T1 of (int * float)

  let doit x = (x, float_of_int x)
  let myT1 x = T1(doit x)

I haven't taken a look at the FAQs, whether this misunderstanding is
already explained there. In any case, it should be mentioned somewhere,
because it is a somewhat surprising fact (if you haven't seen it before).
It is especially difficult to find the bug if you create data in C the
wrong way and wonder why the program keeps crashing: in contrast to the
multi-argument case the tuple case is represented internally with an
indirection...

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl




  reply	other threads:[~2000-02-22 10:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-18 20:47 David McClain
2000-02-21 19:31 ` Markus Mottl [this message]
2000-02-25 14:28 ` Xavier Leroy
2000-02-21 18:02 Don Syme

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=200002211931.UAA03460@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=caml-list@inria.fr \
    --cc=dmcclain@azstarnet.com \
    /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).