Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] small_exercise
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ 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
> > 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