From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA07983; Tue, 18 Nov 2003 19:47:18 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA08560 for ; Tue, 18 Nov 2003 19:47:16 +0100 (MET) Received: from mail2.tpgi.com.au (mail.tpgi.com.au [203.12.160.58]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hAIIlE128895 for ; Tue, 18 Nov 2003 19:47:15 +0100 (MET) Received: from 203-219-235-3-syd-ts26-2600.tpgi.com.au (203-219-235-3-syd-ts26-2600.tpgi.com.au [203.219.235.3]) by mail2.tpgi.com.au (8.12.10/8.12.10) with ESMTP id hAIIkvjg013755; Wed, 19 Nov 2003 05:47:00 +1100 Subject: Re: [Caml-list] GC and file descriptors From: skaller Reply-To: skaller@ozemail.com.au To: Martin Berger Cc: Caml Mailing List In-Reply-To: <3FBA4D97.9060309@dcs.qmul.ac.uk> References: <1069168323.18363.83.camel@pelican> <3FBA4D97.9060309@dcs.qmul.ac.uk> Content-Type: text/plain Message-Id: <1069177584.18363.204.camel@pelican> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 19 Nov 2003 04:46:25 +1100 Content-Transfer-Encoding: 7bit X-Kaspersky-Antivirus: Passed X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ozemail:01 abstraction:01 templated:01 gotos:01 expressive:01 subtyping:01 ocaml:01 descriptors:01 behaviour:01 concise:01 float:02 float:02 exception:02 exception:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 2003-11-19 at 03:49, Martin Berger wrote: > but isn't this snowballing exactly what you want? No. The problem is it breaks abstraction. In C++, the problem was for a templated higher order function .. which is common if you remember classes have methods .. there is no way to tell what exceptions a user defined function passed as an argument might throw. You cannot simply use a type constraint because it amounts to a restriction on the implementation. For example consider map f list which currently has signature ('a -> 'b) -> 'a list -> 'b list Well, how do you account for a function such as: let f x = 1 divide x which might throw division by zero? The only real solution is to not use exception specifications at all in higher order functions... which makes them pretty useless in a language like C++ or Ocaml. > you can > think of exceptions and normal function returns as well- > behaved value-passing gotos. but nobody wants to ignore > intermediate types in function chaining. so why should > only the functional but not the exception behaviour be > constraint by types? the only difference between exceptions > and function types is that > > * for exceptions, the normal case is that we ignore the exception, > i.e., all we do is pass it on, without touching it. > > * for functions, the normal case is to take the returned value > and do something with it. The problem is that exceptions thrown are typically implementation details so it would often be an error to include the exception type in the function signature. In my own code (Felix) I am systematically changing which exceptions report errors -- initially I just called Failure. Now I call exceptions that report source code locations... but this isn't really a change in the type of the function throwing such an error. > i always wonder if problem would simply disappear with more > expressive typing systems that allow concise specification > of the normal case for exceptions -- where an piece of code is > just a conduit for exceptions -- and appropriate grouping of > exceptions, for example by subtyping. Well, exceptions are 'really' wrong: they're 'really' a constraint on the type of the argument, for example divide: float -> float not zero -> float but expressed negatively (throws divide by zero). We can actually do this now, sort of, using classes: class float_not_zero x = if x <> 0 then v := x else raise Invalid_argument sort of thing. However, it is expensive (the best way to test if a matrix is singular is to invert it .. so what constraint can the inversion function have?) and it is generally TOO restrictive to want to transmit through the type system algebraically. Normally, if you think it is important enough you'd use a class to create a new type. ------------------- 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