Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Strange parsing of with-clauses
@ 2004-11-29 16:26 Richard Jones
  2004-11-29 16:46 ` [Caml-list] " Alex Baretta
  2004-11-29 17:04 ` Olivier Andrieu
  0 siblings, 2 replies; 4+ messages in thread
From: Richard Jones @ 2004-11-29 16:26 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 821 bytes --]

Not a big problem, but strange nevertheless:

# exception E of string * string;;
exception E of string * string
# let f () = raise (E ("a", "b"));;
val f : unit -> 'a = <fun>
# try f (); failwith "Not found" with E (a,b) -> (a,b);;
- : string * string = ("a", "b")
# try f (); failwith "Not found" with E t -> t;;
                                       ---
The constructor E expects 2 argument(s), but is here applied to 1 argument(s)

(In my actual code I want to return the thrown tuple to the caller).

Rich.

-- 
Richard Jones.  http://www.annexia.org/  http://www.j-london.com/
>>>   http://www.team-notepad.com/ - collaboration tools for teams   <<<
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
Use Perl libs in OCaml - http://www.merjis.com/developers/perl4caml

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Strange parsing of with-clauses
  2004-11-29 16:26 Strange parsing of with-clauses Richard Jones
@ 2004-11-29 16:46 ` Alex Baretta
  2004-11-29 17:04 ` Olivier Andrieu
  1 sibling, 0 replies; 4+ messages in thread
From: Alex Baretta @ 2004-11-29 16:46 UTC (permalink / raw)
  To: Richard Jones; +Cc: caml-list

Richard Jones wrote:
> Not a big problem, but strange nevertheless:
> 
> # exception E of string * string;;
> exception E of string * string

Exception E is a constructor accepting two arguments, not a single tuple 
of two elements.

> # let f () = raise (E ("a", "b"));;
> val f : unit -> 'a = <fun>
> # try f (); failwith "Not found" with E (a,b) -> (a,b);;
> - : string * string = ("a", "b")
> # try f (); failwith "Not found" with E t -> t;;
>                                        ---
> The constructor E expects 2 argument(s), but is here applied to 1 argument(s)
> 
> (In my actual code I want to return the thrown tuple to the caller).

This is the point.

Try

exception E of (string*string)


or

type thrown_tuple = string * string
exception E of thrown_tuple

> Rich.
> 

Alex

-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Strange parsing of with-clauses
  2004-11-29 16:26 Strange parsing of with-clauses Richard Jones
  2004-11-29 16:46 ` [Caml-list] " Alex Baretta
@ 2004-11-29 17:04 ` Olivier Andrieu
  2004-11-29 19:41   ` Stefan Monnier
  1 sibling, 1 reply; 4+ messages in thread
From: Olivier Andrieu @ 2004-11-29 17:04 UTC (permalink / raw)
  To: rich; +Cc: caml-list

 Richard Jones [Mon, 29 Nov 2004]:
 > Not a big problem, but strange nevertheless:
 > 
 > # exception E of string * string;;
 > exception E of string * string
 > # let f () = raise (E ("a", "b"));;
 > val f : unit -> 'a = <fun>
 > # try f (); failwith "Not found" with E (a,b) -> (a,b);;
 > - : string * string = ("a", "b")
 > # try f (); failwith "Not found" with E t -> t;;
 >                                        ---
 > The constructor E expects 2 argument(s), but is here applied to 1
 > argument(s)
 > 
 > (In my actual code I want to return the thrown tuple to the
 > caller).

Ah no, the issue is not with the `with' clause but with the exception
definition. `E of string * string' defines an exception with two
arguments of type string, which has a different representation than an
exception with one argument of type "tuple of strings". The latter
should be defined as `E of (string * string)'. There's the same issue
with variant types (but not the polymorphic ones !).

-- 
   Olivier


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Strange parsing of with-clauses
  2004-11-29 17:04 ` Olivier Andrieu
@ 2004-11-29 19:41   ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2004-11-29 19:41 UTC (permalink / raw)
  To: caml-list

> definition. `E of string * string' defines an exception with two
> arguments of type string, which has a different representation than an
> exception with one argument of type "tuple of strings". The latter
> should be defined as `E of (string * string)'. There's the same issue
> with variant types (but not the polymorphic ones !).

I think this is another place where Haskell got it right: make those
constructors curried so that it's obvious that it's not carrying a tuple.


        Stefan


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-11-29 19:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-29 16:26 Strange parsing of with-clauses Richard Jones
2004-11-29 16:46 ` [Caml-list] " Alex Baretta
2004-11-29 17:04 ` Olivier Andrieu
2004-11-29 19:41   ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox