Browse thread
[Caml-list] small_exercise
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pierre Weis <pierre.weis@i...> |
| Subject: | Re: [Caml-list] small exercise |
> 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