Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] int -> byte array (and back)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@o...>
Subject: Re: [Caml-list] int -> byte array (and back)
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