From: Pierre Weis <pierre.weis@inria.fr>
To: xavier.leroy@inria.fr (Xavier Leroy)
Cc: altavillasalvatore@libero.it, caml-list@inria.fr
Subject: Re: [Caml-list] small exercise
Date: Fri, 29 Nov 2002 19:29:47 +0100 (MET) [thread overview]
Message-ID: <200211291829.TAA02756@pauillac.inria.fr> (raw)
In-Reply-To: <20021129162957.C27468@pauillac.inria.fr> from Xavier Leroy at "Nov 29, 102 04:29:57 pm"
> > input: string "1.15.120.13.43.35.340.190.0"
> > output: int array= [| 1; 15; 120; 13; 43; 35; 340; 190; 0; |]
>
> That's easy:
>
> let answer_to_the_exercise = function
> "1.15.120.13.43.35.340.190.0" ->
> [| 1; 15; 120; 13; 43; 35; 340; 190; 0; |]
>
> I'm sure your professor will love this solution, as it is not only
> correct w.r.t. the specification, but also quite concise.
As a long time Caml teacher, I would prefer this one :)
let answer_to_the_exercise = function
| "1.15.120.13.43.35.340.190.0" -> | 1; 15; 120; 13; 43; 35; 340; 190; 0; |]
| _ -> assert false;;
Never show a student a non exhaustive pattern matching :)
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:29 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 [this message]
2002-11-29 15:30 ` Christophe Raffalli
2002-11-29 18:48 ` Pierre Weis
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=200211291829.TAA02756@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=altavillasalvatore@libero.it \
--cc=caml-list@inria.fr \
--cc=xavier.leroy@inria.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