caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Thomas Fischbacher <Thomas.Fischbacher@Physik.Uni-Muenchen.DE>
To: Olivier Andrieu <andrieu@ijm.jussieu.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How to raise_with_arg() a tuple?
Date: Fri, 8 Jul 2005 17:55:38 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0507081727090.25669@katrin.cip.physik.uni-muenchen.de> (raw)
In-Reply-To: <17101.30588.827486.654309@karryall.dnsalias.org>


On Thu, 7 Jul 2005, Olivier Andrieu wrote:

>  > exception Test_exn of int * int
> 
> It's the usual gotcha with variant constructor that have multiple
> arguments. The exception you defines has two arguments, whereas 
> 
>  exception Test_exn of (int * int)
> 
> has only one argument -- a tuple. It's not the same thing.

Oh dear. Indeed, if I just put parens around int * int, then everything is fine.

I don't know how other readers on the list think about this, but somehow 
I consider this a pretty bad tripwire. After all, I would not have 
expected behaviour like this:

# type foo =
 | Foo1 of int * int
 | Foo2 of (int * int)
;;
      type foo = Foo1 of int * int | Foo2 of (int * int)
# Foo1 (2,3);;
- : foo = Foo1 (2, 3)
# Foo2 (2,3);;
- : foo = Foo2 (2, 3)
# let x = (2,3) in Foo1 x;;
Characters 17-23:
  let x = (2,3) in Foo1 x;;
                   ^^^^^^
The constructor Foo1 expects 2 argument(s),
but is here applied to 1 argument(s)
# let x = (2,3) in Foo2 x;;
- : foo = Foo2 (2, 3)
# Foo1 2 3;;
Characters 7-8:
  Foo1 2 3;;
         ^
Syntax error

While it is certainly nice that there is an OCaml equivalent (I presume) 
of what would be written in Haskell as:

data Foo =
    Foo1 (Int,Int)
  | Foo2 Int Int
    deriving Show

Main> :load /tmp/1.hs
Main> Foo1 (2,3)
Foo1 (2,3)
Main> Foo2 2 3
Foo2 2 3

(I did not know about this so far!), the syntax used by ocaml certainly is 
quite misleading. As well, it seems to be a bit un-orthogonal here: after 
all, I cannot do this in OCaml (while it is allowed in Haskell, and might 
also be quite useful occasionally):

# Foo1 2;;
Characters 0-6:
  Foo1 2;;
  ^^^^^^
The constructor Foo1 expects 2 argument(s),
but is here applied to 1 argument(s)

Just as a further question, not to be meant as a suggestion or wishlist 
item: would it be conceivable that, at some point in the future, all the 
ocaml tools that operate on .ml files could accept different 
official "syntax variants" (say, the present one and a cleaned up syntax 
to be defined in the future), and dispatch between parsers via some 
command line argument or argv[0]? So that minor issues with the syntax 
could be repaired, should they turn out to be a problem.

> actually it's ok to raise exception directly (ie, not through
> CAMLreturn), the runtime takes care of releasing the local GC roots.

Many thanks again for your explanation.

-- 
regards,               tf@cip.physik.uni-muenchen.de              (o_
 Thomas Fischbacher -  http://www.cip.physik.uni-muenchen.de/~tf  //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y)           V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1))                  (Debian GNU)


  reply	other threads:[~2005-07-08 15:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-07 18:05 Thomas Fischbacher
2005-07-07 18:42 ` [Caml-list] " Olivier Andrieu
2005-07-08 15:55   ` Thomas Fischbacher [this message]
2005-07-08 16:24     ` Kenneth Knowles
2005-07-08 16:58       ` Thomas Fischbacher

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.LNX.4.61.0507081727090.25669@katrin.cip.physik.uni-muenchen.de \
    --to=thomas.fischbacher@physik.uni-muenchen.de \
    --cc=andrieu@ijm.jussieu.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).