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 UAA26148; Thu, 29 Jan 2004 20:19:01 +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 UAA25897 for ; Thu, 29 Jan 2004 20:18:54 +0100 (MET) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i0TJIrv05150 for ; Thu, 29 Jan 2004 20:18:53 +0100 (MET) Received: from force.stwing.upenn.edu (root@force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (8.12.10/8.12.9) with ESMTP id i0TJIqiV026289 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Jan 2004 14:18:52 -0500 (EST) Received: from force.stwing.upenn.edu (wlovas@localhost [127.0.0.1]) by force.stwing.upenn.edu (8.12.10/8.12.9) with ESMTP id i0TJIpLN013134 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Jan 2004 14:18:51 -0500 (EST) Received: (from wlovas@localhost) by force.stwing.upenn.edu (8.12.10/8.12.9/Submit) id i0TJIpu0013133 for caml-list@inria.fr; Thu, 29 Jan 2004 14:18:51 -0500 (EST) Date: Thu, 29 Jan 2004 14:18:50 -0500 From: William Lovas To: caml-list@inria.fr Subject: Re: fancy types (was Re: [Caml-list] ocaml killer) Message-ID: <20040129191849.GA9427@force.stwing.upenn.edu> Mail-Followup-To: caml-list@inria.fr References: <20040127063230.GA12482@inv_machine> <200401282326.i0SNQntl004612@bismarck-chet.watson.ibm.com> <40184A2F.6040007@dcs.qmul.ac.uk> <200401290000.i0T00ntl006988@bismarck-chet.watson.ibm.com> <40184FB9.4000808@dcs.qmul.ac.uk> <200401290034.i0T0Yutl009000@bismarck-chet.watson.ibm.com> <20040129162048.GA29094@force.stwing.upenn.edu> <401945DB.4030106@ps.uni-sb.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <401945DB.4030106@ps.uni-sb.de> User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; lovas:01 wlovas:01 stwing:01 caml-list:01 2004:99 rossberg:01 -rectypes:01 nonobvious:01 val:01 instructive:01 val:01 typeful:01 typechecks:01 encode:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Jan 29, 2004 at 06:41:47PM +0100, Andreas Rossberg wrote: > Also note that you can encode most of these examples without -rectypes, > using variant types. In case it's nonobvious, have a gander at this: # type ('a, 'b) specialist = S of (('a, 'b) specialist -> 'a -> 'b);; type ('a, 'b) specialist = S of (('a, 'b) specialist -> 'a -> 'b) # let fac n = let do_rec (S specialist) n = if n = 0 then 1 else n * specialist (S specialist) n in do_rec (S do_rec) n;; val fac : int -> int = It's also instructive to look at the new, improved type of do_rec: val do_rec : (int, int) specialist -> int -> int = In my experience, type errors have never indicated a lack of flexibility in the typechecker, but rather a lack of understanding on my own part of the code i'm trying to write or the problem i'm trying to solve. And it nearly always pays off in the end to pause for a moment and attempt to assign appropriate types to my functions -- then, when i'm finished, i actually *understand* why the code should work. This is probably why it so often seems to be the case that in typeful programming, "once it typechecks, it works!" cheers, William ------------------- 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