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 UAA03968; Sun, 26 Jan 2003 20:35:04 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA03803 for ; Sun, 26 Jan 2003 20:35:03 +0100 (MET) Received: from hirsch.in-berlin.de (hirsch.in-berlin.de [192.109.42.6]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h0QJZ2r02791 for ; Sun, 26 Jan 2003 20:35:02 +0100 (MET) Received: from hirsch.in-berlin.de (localhost [127.0.0.1]) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with ESMTP id h0QJZ24X016879 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT) for ; Sun, 26 Jan 2003 20:35:02 +0100 Received: from first.UUCP (uucp@localhost) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with UUCP id h0QJZ2Oh016871 for inria.fr!caml-list; Sun, 26 Jan 2003 20:35:02 +0100 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: inria.fr!caml-list Received: by first.in-berlin.de via sendmail from stdin id (Debian Smail3.2.0.114) Sun, 26 Jan 2003 20:28:39 +0100 (CET) From: oliver@first.in-berlin.de (Oliver Bandel) Date: Sun, 26 Jan 2003 20:28:39 +0100 To: caml-list@inria.fr Subject: Re: [Caml-list] Discarding elements from a list Message-ID: <20030126192839.GA486@first.in-berlin.de> References: <20030126190116.GA360@first.in-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030126190116.GA360@first.in-berlin.de> User-Agent: Mutt/1.3.28i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Jan 26, 2003 at 08:01:16PM +0100, Oliver Bandel wrote: [...] > > a) Converting the list to an array, shorten the array, > converting back to a list, using the list in a functional > manner. > > b) Using pattern match to throw away the first element, then > working in the part after the "->" with a function, which > works on the rest of the list. > > c) using a function, which uses an index, for counting, at which > position we are inside of the list OK, I've found a very simple solution. :) OK, it is functional programming..... OK, it is Ocaml... OK, I use pattern matching.... OK, this is my solution: let discard_first lis = match lis with [] -> [] | hd::tl -> tl So, the main way to get a solution to a program in fp is simply: write a function for the simplest case, and then use that function... The last days I often, over and over again found, that I most of the times think more complicated, than a solution in FP is! Maybe this "think complicated" is an imperative illness. (?!) And more and more I see, what the difference between FP and IP is: It's much more easy than an IP-programmer thought that it is. It's unbelievable, that I every day see more examples of how easy programming can be, if it is functional. nearly unbelievable.... Ciao, Oliver ------------------- 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