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 TAA03878; Fri, 29 Nov 2002 19:48:22 +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 TAA03599 for ; Fri, 29 Nov 2002 19:48:22 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gATImKX09522; Fri, 29 Nov 2002 19:48:20 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA03861; Fri, 29 Nov 2002 19:48:20 +0100 (MET) From: Pierre Weis Message-Id: <200211291848.TAA03861@pauillac.inria.fr> Subject: Re: [Caml-list] small exercise In-Reply-To: <3DE78822.7020304@univ-savoie.fr> from Christophe Raffalli at "Nov 29, 102 04:30:42 pm" To: raffalli@univ-savoie.fr (Christophe Raffalli) Date: Fri, 29 Nov 2002 19:48:20 +0100 (MET) Cc: altavillasalvatore@libero.it, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > altavillasalvatore@libero.it wrote: > > Hi all, > > > > I do not succeed to develop the following exercise: > > I have need of your aid. > > > > > > > > input: string "1.15.120.13.43.35.340.190.0" > > > > output: int array= [| 1; 15; 120; 13; 43; 35; 340; 190; 0; |] > > > > : string -> int array > > > > > > Regards. [...] > Just a hint look at the documentation of the following functions: > > module | function > ------------------------------ > str | split > list | map > pervasives | int_of_string > array | of_list > > The answer fits on one (long) line. > -- > Christophe Raffalli I guess, you forgot the most appropriate module for the exercicise: Scanf. Indeed, scanning the given input string to obtain the expected vector only using Scanf.scanf is interesting and not completely trivial. An additional question could be: write a general polymorphic reader that can input vectors with elements of any simple basic type (say bool, int, string, char, float). Define a string reader via partial application of the polymorphic reader. Last but not least could be: generalize (if necessary) the polymorphic reader to read vectors of any given type. Apply this function to read matrices of floating point numbers. Discuss the use of Scanf in place of a combination of modules Str, List, Pervasives, Array, ... Mmm. A trivial exercicise could show up to be interesting afterwards :) Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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