<sam_>
hmm.. does the standard library have a function for binary output/input of a float ? That is, other than input/output_value ?
<whee>
scanf?
<Dybbuk>
Howdy guys.
<sam_>
scanf does not do binary
<whee>
no idea then :|
<sam_>
guess i just need to code my own.. easy enough, but i just find it really annoying that the standard library is missing such 'elemental' stuff
<whee>
the standard library is a bit lacking in some places, I agree
<Dybbuk>
whee: What do you mean by "binary"?
<Dybbuk>
whee: You can marshall and un-marshall floats.
<whee>
wrong person :)
<Dybbuk>
Er, whomever. :)
<whee>
I believe input_value does deal with marshalled values
<whee>
I could be entirely wrong, though. it just seems like that's the easy way to do it
<sam_>
Dybbuk: binary representation.. yes, you can use marshaller to input/output binary floats, but the problem is the marshaller is not type safe
<Dybbuk>
sam_: Whose binary representation?
<sam_>
Dybbuk: a binary representation of a float
<Dybbuk>
I didn't realize there was only one.
<sam_>
so yes, you can use the marshaler to do it (or input/output_value that interface the marshaler).. and you can only have your application core dump if reading in corrupted data.. unfortunately the second case isn't acceptable for real life applications
<Dybbuk>
sam_: Right, but binary representations are usually architecture-specific.
<Dybbuk>
And even then, if you're reading from another piece of hardware, it might be completely different.
<sam_>
dybbuk, oh, sure, there are many binary representations of course.. but i don't really case which, as long as i can input and output in using whichever representation
<Dybbuk>
Usually if you can figure out the representation, you just write your own converter. It is a pain in the ass, though.
<Dybbuk>
What kind of data source are you reading from?
<sam_>
dybbuk, yes.. as said above, writing one would be easy, but such an elemental thing should be in the standard library
<Dybbuk>
Except it's tough to put in the standard library when there's no real standard way to do it.
<whee>
but isnt it?
<sam_>
forget it.. i got the point clear: the standard library does not have one. so i'll write my own
<whee>
there's no way to ensure type safety
<sam_>
dybbuk, there _are_ standard ways to do it.. e.g. IEEE presentations.. it's done all the time in other languages
<sam_>
whee, there _are_ ways to ensure type safety
<whee>
apparently not what you require, as ocaml will most likely die if you request a float to be read and you don't get one
<sam_>
whee, sure there is
<Dybbuk>
sam_: Ah, found it.
<Dybbuk>
sam_: Check the Int64 module.
<Dybbuk>
val bits_of_float : float -> int64
<Dybbuk>
val float_of_bits : int64 -> float
<Dybbuk>
Converts IEEE format.
<Dybbuk>
Or at least 'the IEEE 754 floating-point ``double format'' bit layout'
<sam_>
dybbuk, yes, i know it's there, but that was not the point
<Dybbuk>
But the code might give you someplace to start if you're working with a different float format.
<Dybbuk>
Oh, I guess I don't get the point then.
Kinners has joined #ocaml
<whee>
I don't either. heh
<sam_>
dybbuk, i was asking if there was a standard library function for outputting/inputting floats. not how to write one
<whee>
there is, input_value :P
<sam_>
whee, yeah, but it's not type safe, so it's useless
<whee>
how is it not type safe?
<sam_>
whee, read the documentations of the marshal module
<whee>
so how do you propose implementing type safety? :P
<whee>
it's already platform specific, and assuming you don't write bad code it's not a problem
<sam_>
whee, i'm not proposing anything.. there's several easy ways to do that.. take a look at GCaml for example, or if you are not into extending a language, it's trivial to do it within ocaml, parse the data, and if the data is corrupt raise an exception
greg_ has quit ["Client Exiting"]
<whee>
how would you detect if it's corrupt if you don't know what you're dealing with?
<sam_>
i'm not here to teach programming
<whee>
I'm referring to how you would represent this read value in a strongly typed language
<whee>
since you can't represent it as any type if you don't know what it is.
<sam_>
input_float : in_channel -> float
<whee>
that doesn't explain how you would represent the value you read from the file :P
<sam_>
type safety does not have anything to do with representations in a file
<whee>
type safety means knowing the type of everything and ensuring it's consistent
<sam_>
any representation is ok, as long as the functions inputing/outputing from the representation are type safe
<whee>
there's no way you can possibly know that you're going to read a value of some type from a channel
<whee>
unless you store the type along with the value
<whee>
but even then, how do you know the type is correct
<sam_>
you're confusing type safety and representation there
<whee>
not really
<sam_>
ok, whatever. i'll just ignore you
<whee>
I don't see what's wrong with from_channel and specifying a return type
<Dybbuk>
sam_: Maybe you'd get better results asking on caml-list.
<sam_>
already got my answer about 50 lines up
<sam_>
oh, and sorry if i came across rude. was not my intention