caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Sven LUTHER <luther@dpt-info.u-strasbg.fr>
To: Sven LUTHER <luther@dpt-info.u-strasbg.fr>
Cc: Hao-yang Wang <hywang@pobox.com>, caml-list@inria.fr
Subject: Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
Date: Mon, 2 Apr 2001 13:07:12 +0200	[thread overview]
Message-ID: <20010402130712.A5083@lambda.u-strasbg.fr> (raw)
In-Reply-To: <20010401221502.B635@lambda.u-strasbg.fr>; from luther@dpt-info.u-strasbg.fr on Sun, Apr 01, 2001 at 10:15:02PM +0200

On Sun, Apr 01, 2001 at 10:15:02PM +0200, Sven LUTHER wrote:
> let f1 = function
>   | 'A x -> xxx
>   | 'B x,y -> xx
> 
> 
> and later : 
> 
> let f1 = function
>   | 'C x,y,z -> xxx
>   | x -> f1 x
> 

I was trold that this would not work, which after a bit of experimenting is
true :

        Objective Caml version 3.01
# let f1 = function
  | `A x -> 0
  | `B (x,y) -> 1;;
val f1 : [< `A of 'a | `B of 'b * 'c] -> int = <fun>
#  let f1 = function
  | `C (x,y,z) -> 3
  | x -> f1 x;;
This expression has type [? `C of 'a * 'b * 'c] but is here used with type
  [< `A of 'd | `B of 'e * 'f]

which is not cool, but the following works :

# exception Ea of int;;
exception Ea of int
# exception Eb of int * int ;;
exception Eb of int * int
# exception Ec of int * int * int ;;
exception Ec of int * int * int
# let f1 f = try f () with
  | Ea x -> 0
  | Eb (x,y) -> 1 ;;
val f1 : (unit -> int) -> int = <fun>
# let f2 f = try f () with
  | Ec (x,y,z) -> 2
  | exn -> let f () = raise exn in f1 f;;
val f2 : (unit -> int) -> int = <fun>
# let fa () = raise (Ea 1) ;;
val fa : unit -> 'a = <fun>
# let fb () = raise (Eb (1,2)) ;;
val fb : unit -> 'a = <fun>
# let fc () = raise (Ec (1,2,3)) ;;
val fc : unit -> 'a = <fun>
# f1 fa;;
- : int = 0
# f1 fb;;
- : int = 1
# f2 fc ;;
- : int = 2
# f1 fc;;
Uncaught exception: Ec (1, 2, 3).
# f2 fa;;
- : int = 0
# f2 fb;;
- : int = 1

So there may be some use for the introduction of extensible types (like the
exceptions) after all.

Friendly,

Sven Luther
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  reply	other threads:[~2001-04-02 11:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-30 20:41 Hao-yang Wang
2001-04-01 20:15 ` Sven LUTHER
2001-04-02 11:07   ` Sven LUTHER [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-03-30  8:54 [Caml-list] Interfacing C++ and Ocaml David Chemouil
2001-03-30 16:50 ` Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml) Brian Rogoff
2001-04-02  8:13   ` Jean-Marc Alliot
2001-04-02 13:48     ` Fergus Henderson
2001-04-02 14:30       ` Jean-Marc Alliot
2001-04-02 15:49         ` Brian Rogoff
2001-04-09  6:47           ` John Max Skaller
2001-04-02 15:51     ` Brock

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=20010402130712.A5083@lambda.u-strasbg.fr \
    --to=luther@dpt-info.u-strasbg.fr \
    --cc=caml-list@inria.fr \
    --cc=hywang@pobox.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).