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 VAA27017; Tue, 21 Oct 2003 21:08:05 +0200 (MET DST) 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 VAA13130 for ; Tue, 21 Oct 2003 21:08:04 +0200 (MET DST) Received: from mail.davidb.org (adsl-64-172-240-129.dsl.sndg02.pacbell.net [64.172.240.129]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h9LJ82114688 for ; Tue, 21 Oct 2003 21:08:03 +0200 (MET DST) Received: from davidb by mail.davidb.org with local (Exim 3.36 #1 (Debian)) id 1AC0T6-0005az-00; Tue, 21 Oct 2003 10:38:52 -0700 Date: Tue, 21 Oct 2003 10:38:52 -0700 From: David Brown To: Richard Jones Cc: caml-list@inria.fr Subject: Re: [Caml-list] OCaml wishlist Message-ID: <20031021173852.GA21442@davidb.org> References: <20031021142921.GA6736@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031021142921.GA6736@redhat.com> User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 caml-list:01 wishlist:01 'return':99 foo:01 hash:01 hashtbl:01 hash:01 foo:01 casts:01 java's:01 model:01 model:01 ocaml:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, Oct 21, 2003 at 03:29:21PM +0100, Richard Jones wrote: > 1. 'return' from a function. eg: > > let foo x = > if x < 0 then return "OSL"; > (* long & complex code *) > return "some other string" let return x = x > 2. abstract data type syntactic sugar: > > let hash = Hashtbl.create 16 in > hash#add "foo" 10; or: hash->add "foo" 10; > hash#add "bar" 20; or: hash->add "bar" 20; > > The syntactic sugar is that if a module contains a type called > M.t (literally "type t"), and obj has type M.t, then: > > obj#call [ or: obj->call ] > > is exactly equivalent to: > > M.call obj As pointed out in another post, there are type issues with this. These new constructs have to be polymorphic in the same ways that objects are. If you want an object interface to something, it is probably best to just do it that way. > I think this change would help a lot of Java programmers () who > would otherwise tend to jump immediately on using objects, which are > an area where OCaml is weaker. I'm curious what the argument for Ocaml objects being weaker is. For the most part, the OCaml object system is much more flexible, mostly because class inheritance and type inheritance are kept seperate. Are you complaining that coersion has to be explicit, and that you can't cast to a more specific type? I would suspect most instances of needing these casts in Java is due to Java's much weaker type system. There are some problems where an OO solution maps well to the problem. There are many other problems where trying to force it into an OO model only obscures the problem. Ocaml is nice in that it gives you a choice. The flexibility occasionally means that a particular model may not be as easy to use as in a language where that is the only model available. Dave ------------------- 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