From: Pierre Weis <pierre.weis@inria.fr>
To: raffalli@univ-savoie.fr (Christophe Raffalli)
Cc: altavillasalvatore@libero.it, caml-list@inria.fr
Subject: Re: [Caml-list] small exercise
Date: Fri, 29 Nov 2002 19:48:20 +0100 (MET) [thread overview]
Message-ID: <200211291848.TAA03861@pauillac.inria.fr> (raw)
In-Reply-To: <3DE78822.7020304@univ-savoie.fr> from Christophe Raffalli at "Nov 29, 102 04:30:42 pm"
> 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
next prev parent reply other threads:[~2002-11-29 18:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-29 15:19 altavillasalvatore
2002-11-29 15:29 ` Xavier Leroy
2002-11-29 18:29 ` Pierre Weis
2002-11-29 15:30 ` Christophe Raffalli
2002-11-29 18:48 ` Pierre Weis [this message]
2002-11-29 15:32 ` Jean-Christophe Filliatre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200211291848.TAA03861@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=altavillasalvatore@libero.it \
--cc=caml-list@inria.fr \
--cc=raffalli@univ-savoie.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).