<lus|wazze>
let this_fun_uses_show ?(show = fun _ -> "") ... = ...;;
hitachi has joined #ocaml
Kinners has joined #ocaml
two-face has joined #ocaml
<exa>
I didn't quite understand
<exa>
was ? optonal
<exa>
optional arg?
<lus|wazze>
yep
<exa>
passing it around as an argument doesn't seem like a very good idea
<exa>
i could do this stuff easily in C++
<lus|wazze>
well there is no overloading in ocaml
<lus|wazze>
but if you want to put it into classes you could easily do that, as well
<lus|wazze>
class type showable = object method show : string end;;
<exa>
it's a little frustrating
<exa>
looks very natural you know
<lus|wazze>
i don't really understand what you'd need it for?
<exa>
i'm developing some data structs and i wanna debug them, for instance
<exa>
i know the interpreter can "show" values, so i wanna do the same!
<lus|wazze>
I'm well aware of quite a few shortcomings in ocaml, but lack of a general-purpose to_string function is not really one of them
<lus|wazze>
hmm
<lus|wazze>
for print debugging, eh?
<exa>
yes, for instance
<lus|wazze>
why don't you simply call your function from the toplevel to see whether or not it works?
<lus|wazze>
well besides print-debugging what other use would there be?
<lus|wazze>
i mean
<exa>
what do you think would be?
<lus|wazze>
as long as every type has an associated foo_to_string functiopn
<exa>
I can easily write down the data structures in a text file in haskell
<lus|wazze>
there is the marshalling module in ocaml
<exa>
and use them as input or transfer between codes
<exa>
no that doesn't do the trick
<exa>
i can't edit them with hand
<lus|wazze>
but really i would do this with my own system
<lus|wazze>
then use lisp :)
<lus|wazze>
nothing beats lisp in THAT regard
<exa>
if you've used haskell you'd know what i mean
<exa>
yea maybe
<exa>
but the read/show functions are very useful things
<lus|wazze>
if you want a readable text representation for every datatype
<lus|wazze>
well
<lus|wazze>
for what YOU want to do you wouldn't really need to have it for EVERY type
<lus|wazze>
for a subset of types which are all defined by YOU it is easy to do
<lus|wazze>
use ocaml's oop system
<lus|wazze>
like i wrote above
<lus|wazze>
make your types classes
<lus|wazze>
class type showable = object method show : string end;;
<exa>
there's a lot of impedence mismatch there I didn't quite like it :)
<lus|wazze>
?
<exa>
the trouble is that there should be one standard way of doing it, so far x_to_string funcions for every module and datatype
<exa>
which is not a good solution
<lus|wazze>
why not?
<exa>
because you want it to work for composite types!
<exa>
like 'a list as I said
<exa>
that's why show/read is useful
<lus|wazze>
of course its useful
<lus|wazze>
but you should stop thinking in haskell when you want to write ocaml code
<lus|wazze>
different programming languages work differently
<exa>
no, what i say is if it weren't for composite types, it would have no meaning
<lus|wazze>
personally, I don't even like if the programming language proscribes what an external representation for types has to look like
<lus|wazze>
i like to implement my own system
<lus|wazze>
like i said above
<lus|wazze>
use
<smkl>
for lists, you have "list_to_string elem_to_string" ...
<exa>
ah, good then
<exa>
i didn't notice!
<exa>
so there is in fact something
<exa>
but i feel it should be more generic
<lus|wazze>
which is exactly one of the possible solutions I posted above:
<lus|wazze>
let this_fun_uses_show ?(show = fun _ -> "") ... = ...;;
<lus|wazze>
?
<lus|wazze>
how could it be more generic?
<lus|wazze>
except, of course, with a show function - which is not possible with ml's type system...
<exa>
by some way to abstract over types like show does, I don't know. it doesn't have to be type classes
<exa>
maybe even the module approach, but i can't construct in my head how to do it well enough
<exa>
so it could be usable
<lus|wazze>
or you could stop thinking in haskell when writing ocaml programs
<exa>
actually i don't think in any particular language when i write programs :)
<Kinners>
are there some camlp4 macros or something that generate printers for your declared types?
<exa>
it looks a little absurd to me that you've got a pretty printing lib and marshalling in the stdlib but no ascii-printing/parsing lib
<lus|wazze>
well you seem to be PRETTY caught up in that haskell "I can simply convert any datatype without knowing what it is into a string as long as it is a member of the showable class" mindset
<lus|wazze>
why?
<exa>
because marshalling is harder than doing that
<exa>
marshalling wants language support, right/
<exa>
?
<smkl>
exa: ocaml has very simple marshalling
<exa>
yea show/read in haskell isn't super-duper either :)
<smkl>
it just about dumps the binary values
Kinners has quit [Read error: 54 (Connection reset by peer)]
Kinners has joined #ocaml
<exa>
yea, but it handles a few things, too....
<exa>
it's evidently simpler than ascii stuff
<exa>
haskell people couldn't yet come up with a working marshalling lib :)
<exa>
i can from experience say that general purpose marshalling is harder
<exa>
anyway, i think my point is clear :)
<exa>
ascii representation is something that all programmers might think of messing with
<smkl>
one way that i use is to have function "show" and then structures for different data types, then you can use stuff like "show (list (list string))" ... it's quite easy to add new functions like "read", and it can be generalized to handle records and sums too
<exa>
Kinners: Obviously something that could be done using p4, both simple parser (read) and printer (show)
<exa>
smkl: definitely, it's a blessing :)
<exa>
smkl: and it simplifies writing test programs :)
<vegai_>
perhaps what you really want is unit tests?
<exa>
no i have 'em thanks :)
<exa>
i just write a test code for each module
<exa>
smkl: you think the right way to do it is with p4?
<exa>
it's profitable to think about problems like this, thank you
<exa>
i want to write a lot of ocaml code eventually so i'd better know
<exa>
i've started a really neat directed graph code. maybe if I make it look like the libs they can include in the stdlib?
<smkl>
dunno. probably not. stdlib is supposed to be very small ie. it just has stuff that is needed in the compiler
<exa>
that's surely not the definition of stdlib :)
<exa>
I mean all main libs
two-face has quit [Read error: 110 (Connection timed out)]
<exa>
where is list_to_string declared?
<smkl>
this is always discussed on the mailing list but i haven't checked what is the current situation
<smkl>
let list_to_string el lst = "[" ^ String.concat ";" (List.map el lst) ^ "]"
<exa>
thx
<exa>
with this the print function will look terrible
<exa>
to_string vtx edge g
<exa>
hm
<marty>
i am writting a ocaml server that listens on a port, but if i shut it down and start it up right after i get an error like this:"Fatal error: exception Unix.Unix_error(50, "bind", "")", and if i wait and try again it'll work. is their some way i can get around this? i've tried to make some code in a signal handler that closes the socket down cleanly but it doesn't work because the socket is blocked on an accept.
<Smerdyakov>
This is a problem with sockets in any language you use
<Smerdyakov>
I think you could say it's a "problem" with TCP/IP, based on how long you have to wait to "really know" a socket is closed.
<marty>
yeah, but other applications, like apache don't have this problem
<Smerdyakov>
I think some flag called REUSEADDR might help.
<Smerdyakov>
I don't remember if it does.
<marty>
hmm, i'll try that. i remember seeing something like that in the documentation
<marty>
Smerdyakov: you're a genius, that did the trick
<marty>
:-)
systems has joined #ocaml
TachYon has quit [Read error: 110 (Connection timed out)]
systems has quit ["Client Exiting"]
marty has quit [Read error: 110 (Connection timed out)]
rox|rauslaufen is now known as rox
lament has quit ["Support Darwin Awards! Join the military!"]
exa has quit [Remote closed the connection]
asqui has joined #ocaml
Kinners has quit [Read error: 104 (Connection reset by peer)]