<flux>
ulfdoz, do you have some nice combinator for implementing printf or scanf -like features without the format string-hack?
<ulfdoz>
flux: No, I really do it the expensive way.
screwt8 has quit [Remote closed the connection]
Abo-Marwan has quit [Remote closed the connection]
<flux>
ulfdoz, you don't think using printf is more succinct or readable than using a sequence of output_string, output_int etc?
<ulfdoz>
flux: I only consider it less weird. Formatstrings are hard to read and confuse typed values and representations.
<flux>
that is somewhat true. however, why aren't representation and types tied?
<flux>
you could represent an integer as a character, if you wished, however for many programmers it would seem reasonable to convert the character into an integer first
<flux>
..and represent that integer as an, well, integer
<ulfdoz>
of course, you could. I'd prefer to have a function like ord : char -> int to get the integer.
<flux>
format strings aren't quite extensible, though
<flux>
and perhaps the requirement of having an arbitrarily chosen character matching a type might feel, well, arbitrary
<flux>
but it's still just so darn convenient ;)
<flux>
but if there was a nice alternative, I would definitely consider it..
<ulfdoz>
Yes, printf/scanf is convenience, but nothing I'd prefer in production code. I sometimes use them for debugging.
<flux>
well, even in production code you might want to produce log entries
<flux>
which are perhaps related to debugging
<flux>
I wonder if the sml approaches would be implementable in ocaml. I've seen some type-system-only-printfs for sml, but I didn't try porting them to ocaml
Abo-Marwan has joined #ocaml
<flux>
if you add camlp4 to the mix something more nicely typeable should be possible
<flux>
and perhaps it would result in something that could be used for constructing sql queries also.. (insert into foo values (?, ?) etc)
<flux>
but, I'm going to sleep now. local time is 0341 and I've had a bit too much to drink.
<ulfdoz>
sleep well.
<flux>
so good night; solutions are still welcome, though ;)
buluca has quit [Remote closed the connection]
buluca has joined #ocaml
<ulfdoz>
unfortunately my current project makes me documenting, debugging and writing java.
[azoic] has joined #ocaml
buluca has quit [Remote closed the connection]
buluca has joined #ocaml
nuncanada has joined #ocaml
leo037 has quit ["urpmi sommeil"]
baruk has quit [Read error: 104 (Connection reset by peer)]
dbueno has quit ["This computer has gone to sleep"]
screwt8 has joined #ocaml
Mr_Awesome has quit [Read error: 110 (Connection timed out)]
[azoic] has quit [Read error: 104 (Connection reset by peer)]
[azoic] has joined #ocaml
pango has quit [Remote closed the connection]
pango has joined #ocaml
nuncanada has quit ["Leaving"]
buluca has quit [Read error: 113 (No route to host)]
piggybox_ has joined #ocaml
piggybox has quit [Connection timed out]
Abo-Marwan14 has joined #ocaml
screwt881 has joined #ocaml
screwt8 has quit [Read error: 104 (Connection reset by peer)]
Abo-Marwan has quit [Read error: 104 (Connection reset by peer)]
[azoic] has quit [Read error: 110 (Connection timed out)]
pantsd has quit [Read error: 110 (Connection timed out)]
pango has quit [Remote closed the connection]
pantsd has joined #ocaml
pantsd has quit [Client Quit]
<jdavis_>
I think something is strange with my installation of ocaml. I can "open Str;;" but when I do "Str.quote" it says "unbound value Str.quote".
jonathanv has joined #ocaml
<jonathanv>
helllllllllp
<jdavis_>
jonathanv: I don't know whether I can help, but ask the question.
<jonathanv>
i want to define a function that reads from a socket and takes a function as a parameter
kelaouchi has joined #ocaml
<jonathanv>
the second function is to be called when data is available and return the function that should be called when more data is available
<jonathanv>
so this function would have a signature like
<jonathanv>
actually ocaml decided the function is just stream -> 'a
<jdavis_>
jonathanv: hmm...
<jonathanv>
i was pretty pleased with this idea when i wrote it out on paper a couple of weeks ago
<jonathanv>
but it doesn't look quite so hot now
<jdavis_>
jonathanv: so the second function is a callback, and what would it return?
<jonathanv>
the next callback
<jdavis_>
oh.
<jdavis_>
so what is "ocamlIsUnhappyWithYou"?
<jonathanv>
as we move through stages in the protocol, it would return various different callbacks
<jonathanv>
ocaml doesn't seem to know how to deal with this concept
<jonathanv>
because the signature of the function is recursive
<jonathanv>
it's essentially doing
pango has joined #ocaml
<jonathanv>
let rec f () -> f;;
<jonathanv>
unit -> (unit -> (unit -> (forever...
<jdavis_>
I kind of see now.
<jonathanv>
so ocaml is just saying the callback returns 'a
<jdavis_>
jonathanv: how are you changing the callback at the different stages of the protocol?
<jonathanv>
well, this protocol has a fixed size header and variable length data after it for each packet
<jdavis_>
is it a protocol stack or just a single header + body that you're trying to process?
<jonathanv>
so the callback reads the data, figures out if it's got the full header, and if it does, it calls the function that reads the payload
<jonathanv>
if not, it returns the function to read the header
<jonathanv>
i don't understand what you mean there
<jdavis_>
if it's a fixed-size header, why don't you just block waiting for X bytes? are you trying to do it all async?
<jonathanv>
yes
<jdavis_>
ok
<jonathanv>
async
ygrek has joined #ocaml
<jonathanv>
yes, i could remove the callback aspect and just hardcode everything together, but that wouldn't be nearly as neat
<jdavis_>
jonathanv: I see what you mean, you want to do something like: let rec f = if true then f else read_payload;; right?
<jonathanv>
yeah, basically
<jonathanv>
i can see why ocaml is confused about the type of the callback
<jdavis_>
jonathanv: that's really returning different function signatures though, right?
<jonathanv>
no
<jonathanv>
both take the same arguments and return the same things
<jonathanv>
but i haven't even gotten to that step
bluestorm_ has joined #ocaml
<jonathanv>
i've only entered in the function that reads from the socket so far
<jdavis_>
jonathanv: I can't be much help I don't think, except that it seems like a function can't really return itself.
<jonathanv>
yeah...
<jdavis_>
If it could, then that would mean that it would have to return functions with different signatures based on a conditional.
<jonathanv>
well, no, that's not it
G_ is now known as G
<jdavis_>
jonathanv: how could you make that work?
<jonathanv>
if you think the read_payload function needs data from the header to work, i am using currying to attach the data from the header to it
<jonathanv>
maybe i can use a variant data type to define the callback
<jdavis_>
jonathanv: I understand that, but if you keep calling the result of a function, eventually it needs to return something that's not a function. So wouldn't that mean that you're getting something back that's not the same type?
<jonathanv>
type callback = CloseSocket | Callback of (int -> callback);;
<jonathanv>
er not int
<jonathanv>
stream
<jonathanv>
i wrote int on the interactive ocaml thingy
<jdavis_>
Oh, that could work.
<jdavis_>
jonathanv: interesting idea. I'm trying it out myself.
<jonathanv>
the interactive ocaml thing thought the type definition with int was okay
<jonathanv>
i'm modifying the socket function now
<jonathanv>
yeah, supposedly it likes it okay
<jdavis_>
jonathanv: cool.
Mr_Awesome has joined #ocaml
oc13 has joined #ocaml
oc13 has left #ocaml []
seafoodX has quit []
jonathanv has quit ["XCHAT NEGROS"]
bluestorm_ has quit ["Konversation terminated!"]
Tetsuo has joined #ocaml
bluestorm_ has joined #ocaml
bluestorm_ has quit ["Konversation terminated!"]
seafoodX has joined #ocaml
seafoodX has quit [Client Quit]
l_a_m has joined #ocaml
joshcryer has quit [Read error: 110 (Connection timed out)]
Mr_Awesome has quit [Read error: 110 (Connection timed out)]
skal has joined #ocaml
love-pingoo has joined #ocaml
kelaouchi has quit ["leaving"]
smimou has joined #ocaml
kelaouchi has joined #ocaml
leo037 has joined #ocaml
<flux>
jonathanv's code works with -rectypes, but using -rectypes can (so I've read) cause obscure error messages (with illegal code)
<flux>
the no-recursive-types-limitation can be avoided witha n intermediate constructor
<flux>
perhaps someone can tell him that when he comes back :)
Demitar has quit [Read error: 110 (Connection timed out)]
baruk has joined #ocaml
pango has quit [Remote closed the connection]
pinskian has joined #ocaml
pinskian has left #ocaml []
buluca has quit [Read error: 113 (No route to host)]
leo037 has quit [Remote closed the connection]
leo037 has joined #ocaml
[azoic] has joined #ocaml
pango has joined #ocaml
buluca has joined #ocaml
<jdavis_>
flux: what's an n intermediate constructor?
seafoodX has quit []
buluca has quit [Read error: 113 (No route to host)]
ita is now known as ita|nap
buluca has joined #ocaml
ita|nap has quit [Read error: 110 (Connection timed out)]
jlouis has joined #ocaml
rwmjones has left #ocaml []
smimou has quit ["bli"]
<jdavis_>
I have a file "s.ml" and it uses the function "Str.quote". I do "ocamlfind ocamlopt -o s s.ml" but I get "No implementations provided for the following modules: Str referenced from s.cmx"
buluca has quit [Read error: 113 (No route to host)]
<jdavis_>
Is something wrong with my installation? It seems like I should have the Str module.
<bluestorm_>
jdavis_:
<bluestorm_>
add
<bluestorm_>
str.cmxa
<bluestorm_>
ocamlopt str.cmxa ...
<bluestorm_>
Str is in the standard library
<bluestorm_>
but not linked by default
<bluestorm_>
".cmxa" is the name of the native file
<bluestorm_>
if you were using ocamlc you'd need "str.cma"
<jdavis_>
bluestorm_: ah, I thought I wouldn't have to do that because it's part of the standard library
<jdavis_>
Ok, works fine now.
<jdavis_>
thanks.
rutlov has joined #ocaml
buluca has joined #ocaml
<flux>
jdavis_, type foo = unit -> foo is legal only with -rectypes, while type foo = Foo of (unit -> foo) is legal always
<flux>
oh
rutlov has left #ocaml []
<flux>
the phrase had a typo> witha n intermediate -> with an intermediate, I thought people would notice the mistake there
YlandeFaran has joined #ocaml
<flux>
sigh, it can be distracting to use two different keyboard layouts..
<jdavis_>
flux: I'm new to ocaml, so thanks for the explanation.
<jdavis_>
flux: I don't think I fully understand a function that returns itself.
<pango>
jdavis: since you're using ocamlfind, you could use ocamlfind ocamlopt -package str -linkpkg -o s s.ml too
<jdavis_>
pango: Ok, thanks.
<jdavis_>
that worked too.
ygrek has quit [Remote closed the connection]
buluca has quit [No route to host]
bluestorm__ has joined #ocaml
bluestorm_ has quit [Read error: 104 (Connection reset by peer)]
ikaros has joined #ocaml
Demitar has joined #ocaml
ita|nap has joined #ocaml
ita|nap is now known as ita
<YlandeFaran>
I want to construct a do_while function that takes an command and a boolexp. Executes the command at least once, and repeats after that untill boolexp is false.
<YlandeFaran>
I'm starting to think this can't be done w/o the help of some helperfunction... Is there some nice trick I have missed?
<flux>
hmm.. let do_while f p = f (); while p () do f () done ?
<flux>
although I would personally avoid such imperative constructs
<YlandeFaran>
Yes, I would like a nicer recursive solution, but perhaps there are none?
<flux>
a function with type ('a -> (bool * 'a)) -> 'a -> 'a perhaps?
<flux>
perhaps let rec unfold f v0 = let (continue, v) = f () in if continue then unfold f v else v
<YlandeFaran>
I'm sorry, getting way to complicated for me atm.
[azoic] has quit [Read error: 104 (Connection reset by peer)]
<flux>
actually that has a bug (caught by type inference, however), so the real function would be like:
<flux>
let rec unfold f v0 = let (continue, v) = f v0 in if continue then unfold f v else v;;
<ita>
while true and an exception for stopping the loop
<YlandeFaran>
Say that it should stop after 2-3 iterations, it will evaluate c1 one time to many that way, no?
<pango>
if the condition would have become true at the beginning of 'loop', it's not true at the end of the previous loop, because it's evaluated in the same context
<pango>
so I think my implementation is correct
<pango>
s/not/now/
ygrek has joined #ocaml
<YlandeFaran>
Can't se anything wrong with it, so I should be correct.
<YlandeFaran>
Allthough, I have a sneaking feeling that something could be wrong.. :)
<pango>
a more straightforward (but longer) implementation would first run the command once, then implement the usual 'while loop' using an auxiliary recursive function
<pango>
you could try writing both, and convince yourself they're doing the same thing
<bluestorm__>
hum
<bluestorm__>
seems i don't undestand the question,
<bluestorm__>
but what's wrong with let rec do_while f p = f (); if p () then do_while f p ?
Tetsuo has quit ["Leaving"]
Jedai has joined #ocaml
ygrek has quit [Remote closed the connection]
ikaros has quit ["segfault"]
love-pingoo has quit ["Connection reset by pear"]
joshcryer has joined #ocaml
skal has joined #ocaml
bluestorm__ has quit ["Konversation terminated!"]
skal has quit [Remote closed the connection]
hsuh has joined #ocaml
smimou has joined #ocaml
buluca has joined #ocaml
Mr_Awesome has quit ["aunt jemima is the devil!"]
Mr_Awesome has joined #ocaml
leo037 has quit ["Leaving"]
leo037 has joined #ocaml
Mr_Awesome has quit [Read error: 110 (Connection timed out)]
ita has quit ["Hasta luego!"]
<hcarty>
When do you need to use the CAMLparam macros in the C interface?
<hcarty>
Some example code in the manual uses it, some does not
<hcarty>
My understanding from the manual is that all code should use it...
<hcarty>
But, then, camlidl generated code does not seem to at all
leo037 has quit ["urpmi dormo"]
seafoodX has joined #ocaml
Jedai has quit [Read error: 104 (Connection reset by peer)]