From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 44C33BB94 for ; Mon, 3 Oct 2005 18:12:16 +0200 (CEST) Received: from first.in-berlin.de (dialin-145-254-061-089.pools.arcor-ip.net [145.254.61.89]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j93GCE6M018078 for ; Mon, 3 Oct 2005 18:12:15 +0200 Received: by first.in-berlin.de (Postfix, from userid 501) id 41990162D99; Mon, 3 Oct 2005 13:51:20 +0200 (CEST) Date: Mon, 3 Oct 2005 13:51:20 +0200 From: Oliver Bandel To: caml-list@yquem.inria.fr Subject: getting used to FP-programming (Re: Ant: Re: Ant: Re: [Caml-list] Avoiding shared data) Message-ID: <20051003115120.GA481@first.in-berlin.de> References: <20050930225737.GA592@first.in-berlin.de> <20051001213609.88104.qmail@web26808.mail.ukl.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051001213609.88104.qmail@web26808.mail.ukl.yahoo.com> User-Agent: Mutt/1.5.6i X-Miltered: at nez-perce with ID 4341585E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; oliver:01 bandel:01 oliver:01 in-berlin:01 caml-list:01 avoiding:01 ocaml:01 runtime:01 recursive:01 recursive:01 recursion:01 recursion:01 recursions:01 ocaml:01 ...:98 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Hello Martin, On Sat, Oct 01, 2005 at 11:36:08PM +0200, Martin Chabr wrote: > Hello Oliver, > > I am trying to find a programming style within the > spectrum of possibilities which OCaml supports. This > programming style should be easy to produce, easy to > read and efficient in runtime. > > Sometimes a nested system of "for" or "while" loops > appears simpler to me than a system of recursive > calls. Sometimes such systems of recursive calls > remind me of undisciplined goto jumps. [...] > general, for the real world problems, it is much > worse. I cite the author: > "That was a brief overview of tail recursion, but in > real world situations determining if a function is > tail recursive can be quite hard." I believe him. I doubt it is. Or maybe if the people write functions that are some pages of code long. But it's better to keep the functions short, and FP makes this very easy. [...] > I think that some problems, like simple operations on > lists, can be easier described by pattern matching and > recursion, whereas for others it appears more natural > to take loops. Yes, but when you are used to FP-style and recursions the amount of problems one would rather use the for/while loops for, gets smaller. I just dome days ago saw this on an example-code I wrote in a discussion on the berlin' Linux-User-Groups mailing list (I'm doing some marketing for OCaml;-)) I first thought, well the better version is with loops. But I tried the recursive definition and it was astouningly easy to read. :) So IMHO it's how often you tried the different programming style, what makes you thinking different about this. > > I also think that what looks simple or not depends on > the person. I myself have spent half of my life with > imperative languages. Mee too for many years, and "depends on the person" could also be said as: "depends on the experience of the person", and as I more and more get used to FP constructs, I see the problem solving diferently than some time ago. Ciao, Oliver