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 HAA21602; Thu, 20 Nov 2003 07:08:05 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id HAA21310 for ; Thu, 20 Nov 2003 07:08:04 +0100 (MET) Received: from mail1.tpgi.com.au (mail.tpgi.com.au [203.12.160.57]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hAK682119744 for ; Thu, 20 Nov 2003 07:08:02 +0100 (MET) Received: from 203-213-85-204-syd-ts17-2600.tpgi.com.au (203-213-85-204-syd-ts17-2600.tpgi.com.au [203.213.85.204]) by mail1.tpgi.com.au (8.11.6/8.11.6) with ESMTP id hAK663027129; Thu, 20 Nov 2003 17:06:10 +1100 Subject: Re: [Caml-list] int -> byte array (and back) From: skaller Reply-To: skaller@ozemail.com.au To: Dustin Sallings Cc: Caml Mailing List In-Reply-To: <57648B84-1ACF-11D8-A4B7-000393CFE6B8@spy.net> References: <57648B84-1ACF-11D8-A4B7-000393CFE6B8@spy.net> Content-Type: text/plain Message-Id: <1069304729.24578.48.camel@pelican> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 20 Nov 2003 16:05:37 +1100 Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ozemail:01 chasing:01 strangely:01 expressive:01 hashtbl:01 hashtbl:01 semantics:01 semantics:01 ocaml:01 ocaml:01 byte:01 byte:01 int:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 2003-11-20 at 07:31, Dustin Sallings wrote: > I need to be able to get a byte array (specifically in little-endian > format) from an int. I'll need the reverse as well. Is there anything > that does that in the distribution, or do I need to calculate it > myself? Just trying to do things the right way. There is nothing wrong in Ocaml with writing the code yourself. In fact, for simple code like this I recommend *against* using a library function even if it exists. The reason is: for a simple algorithm like this the semantics are manifiest in the encoding, and the reader does not have to go chasing up on the documentation to discover the semantics. If you are used to C/C++ you will find Ocaml libraries strangely bare -- the language is so expressive and efficient many features simply don't need a named, documented, procedure to get right .. for example let make_recording_function () = let h = Hashtbl.create 97 in fun x y -> Hashtbl.add h x y ;; let add = make_recording_function () ;; add 1 "one";; add 2 "two";; let data = [5,"five"; 6, "six"];; iter2 add (split data);; Just try to do that in C++ with classes to see how good Ocaml is .. to make this polymorphic I think you'd need to be a template meta-programming guru :-) ------------------- 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