<alexyk>
flux: so we'd have to do a sudden switch to it I guess? It really bothers me that libraries like List are limited and nobody cares, saying "well just write it"; and we'd have to wait for adoption of Batteries...
<flux>
there is extlib, which the list-part of batteries is based on
<alexyk>
flux: but who decided that List is untouchable?
<flux>
alexyk, no one. you can just release your own List, the license allows it. tada, you've touched it \o/
<flux>
or you can enter a bug report to the ocaml bug tracking system
<flux>
in general the ocaml team is focused on developing the compiler, not so much the library, except for those features that support the compiler (think Printexc)
<alexyk>
flux: ok, that's what I thought
<flux>
but adding "take" to List seems a very minor change. infact, so minor that why bother. and doing a larger revamp is a big task. hence the batteries.
<flux>
adding a few functions would only serve to make the new source incompatible with old compilers
<flux>
implementing take/drop/etc where you need them (which you rarely do, in my opinion) takes only a few lines
<flux>
albeit there are other functions which everyone appears to write, such as calling a function so that its return value is always a value, even if it raises an exception
<flux>
things that everyone implement are nice to be in a standard library.
Kerris7 has joined #ocaml
asabil has quit ["Ex-Chat"]
ulfdoz has joined #ocaml
mtrimpe has quit []
Kerris7 has quit []
mishok13 has joined #ocaml
asabil has joined #ocaml
Yoric has joined #ocaml
tomh has joined #ocaml
tomh has left #ocaml []
ygrek_ has joined #ocaml
glondu has quit [Read error: 104 (Connection reset by peer)]
glondu has joined #ocaml
Kerris7 has joined #ocaml
vixey has joined #ocaml
Kerris7 has quit []
Kerris7 has joined #ocaml
ygrek_ has quit [Remote closed the connection]
Associat0r has joined #ocaml
<alexyk>
I have an ocaml driver calling many unix binaries, and it fails after a while with:
<alexyk>
-- however, I do close all pipes; what is this error?
<pumpkin_>
alexyk: you're up late!
<pumpkin_>
or early
pumpkin_ is now known as pumpkin
<alexyk>
pumpkin: and you? :)
<pumpkin>
alexyk: yeah, gonna go to sleep soon or I'll die tomorrow... just working on my project right now :P
<flux>
alexyk, are you sure you're not writing to a pipe that's closed? possibly by the other end
<alexyk>
I just started running my ocaml-driven research, which is exciting so hard to sleep
<flux>
(well: not "possibly" but exactly by the other end)
<alexyk>
flux: actually I forgot to close channels, yet got exception on a pipe
<flux>
alexyk, yes, but if the other end has closed the pipe and you write to it, you get that exception
<flux>
alexyk, but, there's a solution to it
<flux>
Sys.signal Sys.sigpipe Sys.Signal_ignore
<alexyk>
flux: interesting... but I'm quite sure I don't write into a closed pipe -- I was doing open_in without close_in, somehow it clogged things; could it have caused that pipe error all by itself, e.g. without any more pipes available
<pumpkin>
yeah :P gonna get some sleep first though
<pumpkin>
I want to be energetic tomorrow
<alexyk>
pumpkin: well there's still time ... and I'm going to watch my cool simulation to run out of pipes or something, after an hour or so usually
<pumpkin>
what are you simulating?
<alexyk>
pumpkin: I have a series of ngram models watching a person walk through a sensor field
<alexyk>
it's all in ocaml calling external commands, parsing and aggregating results
<alexyk>
it really all works the first time it compiles, amazing...
<flux>
alexyk, EPIPE comes only from writes, and only when the reading end of the descriptor is closed.
<flux>
alexyk, it's a unix error, you can read more about it with man 2 write
<alexyk>
flux: ok! will check further
<alexyk>
so what would be the result of Sys.signal Sys.sigpipe Sys.signal_ignore then? writing disappearing?
<pumpkin>
alexyk: anyway, good luck with that, I'm hitting the hay :P
<flux>
alexyk, the write will return 0 on EOF
<flux>
alexyk, so likely your exception will just change to End_of_file..
<alexyk>
pumpkin: g'night!
<flux>
hmm, actually
<flux>
I need to check that
<flux>
yeah, actually I think you or some library might have already done that somewhere
<alexyk>
flux: is there a way to open_in ic su that it's closed no matter which way you leave a function?
<flux>
because EPIPE is the return code, not the sigpipe signal
<alexyk>
I forgot to close_in in some places, and when I have several exit points, especially with exception, I have to close_in manually everywhere; I wish I'd have Ruby's or Python's "with file
<alexyk>
" block
<flux>
alexyk, unfortunately no. but you can do this: let with_in name f = let fd = open_in name in let v = try f () with exn -> close_in fd; raise exn in close_in fd; v
<flux>
whops, scratch that
<flux>
let with_in name f = let fd = open_in name in let v = try f fd with exn -> close_in fd; raise exn in close_in fd; v
<alexyk>
flux: intersting! and now I see I'm past the point of EPIPE and all is well when I added close_in ic everywhere... I call external commands and then read/write results, somehow it's related
<flux>
so which Unix.* functions do you use?
<alexyk>
the commands are run with let in_channel = Unix.open_process_in command ... Unix.close_process_in in_channel
<alexyk>
the reads/writes are done with ocaml's usual open/close_in/out
<alexyk>
well I also increased the stack just to be sure :)
<flux>
how do you open the fd you write into?
<alexyk>
flux: open_out
<alexyk>
flux: I don't write to pipes at all
<flux>
alexyk, have you seen the backtrace?
<alexyk>
flux: nope, I've restarted it already and it still works :)
<flux>
alexyk, do you know how to get a backtrace?
<alexyk>
flux: no, how?
<flux>
alexyk, 1) compile with -g 2) export OCAMLRUNPARAM=b
<flux>
3) run
<alexyk>
thx! will definitely try when I run into trouble
<flux>
better do it beforehand, so you have it when you do run the first time :)
<alexyk>
flux: how do I combine b with e.g. l=64M ?
<alexyk>
is it colon-separated?
<flux>
alexyk, I don't remember. likely comma-separated.
<alexyk>
ok
middayc has joined #ocaml
mjrosenb has joined #ocaml
<mjrosenb>
how do i use things from LWT in the repl?
<mjrosenb>
and by things, i mean functions
<flux>
mjrosenb, what is your question more exactly? how to bring them into scope? how to make constructed values to run?
<flux>
I haven't used lwt, but for the latter Lwt_unix.run appears to be the key
fschwidom has joined #ocaml
<flux>
how do you to val spawn : (unit -> 'a Lwt.t) -> 'a Lwt.t in Lwt?
snhmib has joined #ocaml
Kerris7 has quit []
Kerris7 has joined #ocaml
<alexyk>
what's the modern take on calling C++ from ocaml? making it all like C?
<flux>
that's one way
<flux>
one other way, which I haven't traveled, is using Swik
<alexyk>
flux: you mean swig?
<flux>
ah, yes
<alexyk>
it may be easier to rewrite everything in ocaml... :)
<alexyk>
this is where I envy Boost.Python
<flux>
well, there is hope
<flux>
qtcaml apparently is coming up with some c++ binding generator
<flux>
it would be interesting to try it with sfml
ygrek_ has joined #ocaml
seafood has quit []
middayc_ has joined #ocaml
<mjrosenb>
flux: i want to bring them into scope
<flux>
mjrosenb, #require "topfind";;
<flux>
uh
<flux>
#use "topfind";;
<flux>
#require "lwt";;
<flux>
and then refer to Lwt.xx, Lwt_unix.yy etc
<flux>
(or "open" them if you wish)
<mjrosenb>
sweet
<mjrosenb>
is #require "topfind" mentioned anywhere on the inria site?
<flux>
#require "topfind";; was wrong
<flux>
but no, topfind is part of findlib
<mjrosenb>
right.
Kerris7 has quit []
middayc has quit [Read error: 110 (Connection timed out)]
<mjrosenb>
hrmm, i'm trying to find the types of various functions is Eliom
<mjrosenb>
but i keep getting Reference to undefined global `XHTML'
<mjrosenb>
i think my main issue is that i have no clue how to read the types that they specify here
<mjrosenb>
val body : ([< common ], [< block ], [> `Body ]) star
<flux>
well, star is apparently a type that is parametrized by three other types
<flux>
and those three types are all polymorphic variants
<mjrosenb>
what are < and > ?
<flux>
"The > and < inside the variant type shows that they may still be refined, either by defining more tags or allowing less."
<mjrosenb>
fun.
<mjrosenb>
labels seem to break a layer of syntax sugar that i'd preffer to not have broken
<flux>
mjrosenb, hm?
<mjrosenb>
let f x y = ... should be equivalet to let f = fun x -> fun y -> ...
<flux>
well, let f ~x ~y = ... let f = fun ~x -> fun ~y -> ...
<flux>
but you're right that currying doesn't quite work as nicely with labeled arguments
<flux>
but labeled arguments have their places
gdmfsob has joined #ocaml
<flux>
I didn't realize how nice it was that it's called Pcre.exec ~rex str instead of Pcre.exec rex str, until I saw a comment that he'd otherwise never remember the proper argument order
<flux>
I might have issues with that too, but when I remember labeled arguments, it is simpelr
<flux>
of course, Pcre might not be the best example, because it has overlapping definitions: Pcre.exec has both ~rex and ~pat, and nothing stops you from using both, even though you're supposed to use only one of them (?)
<flux>
one other thing which I perhaps like even more is the optional arguments. this is one place where I think they've been implemented right.. (modulo some issue they cause ;-))
<mjrosenb>
i think that there are better ways to implement optional arguments
<flux>
which all involve modifying code that calls the code prior to adding the optional arguments?
<mjrosenb>
what do you mean by 'modifying'?
<flux>
well, one way that has been suggested would be do do f { default_f_args with optional_arg = 42 }
<flux>
that would involve modifying existing code if they haven't taken any optional arguments before
<flux>
mjrosenb, what other ways are you suggesting then?
<mjrosenb>
so the system that i'm thinking of works alot better in haskell
<mjrosenb>
where you have type classes
Yoric has quit [Remote closed the connection]
mishok13 has quit [Read error: 110 (Connection timed out)]
middayc_ has quit [Read error: 60 (Operation timed out)]
middayc has joined #ocaml
ulfdoz has quit [Remote closed the connection]
ulfdoz has joined #ocaml
<flux>
doesn't work for me
<flux>
maybe it tries to open http connection to some port not allowed from work
<vixey>
it's just this program from Coq turned into a java applet via ocaml, I thought that was cool
<flux>
yeah, proven code is cool
<flux>
but it's 6k+ lines for a sudoku solver :)
<flux>
(or 4k for only Sudoku.v)
<flux>
tried it locally. it maybe works, but it's really slow :)
<flux>
yeah, works
<flux>
the ocaml code doesn't come with it.. I doubt the user interface is extracted from Coq..
<flux>
nice, it gives all solutions
dejj has joined #ocaml
<munga>
I've written a small camlp4 parser. now I want to give it a whole file to read and parse I usually use Gram.parse_string to parse line by line. Is there a function to pass the entire file at one ? like Gram.parse_file ?
<munga>
or shall I read the entire file into a buffer and then use parse_string ?
<christo_m>
im trying to write a tail recursive function in the third part there
<christo_m>
i know the first two are correct
<christo_m>
Optikal_, something's wrong with the return type showever, i need (a` -> a`)
<christo_m>
not (int -> int)
<Optikal_>
3rd function?
<christo_m>
Optikal_, yes
<Optikal_>
k
<christo_m>
Optikal_, any ideas?
<Optikal_>
It can't be 'a cause you are inferring it as int..
<christo_m>
well i dont want it to be an int
<Optikal_>
this is a function meant to be used on ints right?
<christo_m>
f is a function im passing
<christo_m>
well, its a function i pass a function, a value n (how many times the recursion should take place) and an argument a for the function f
<christo_m>
so its like
<christo_m>
f^n(a)
<Optikal_>
WHat do you think the function signature should be?
<christo_m>
i have no clue man, thats why im here
<christo_m>
it should return units
<christo_m>
hold on i can show you
<Optikal_>
You don't want the n parameter to be forced as int I'm guessing
<christo_m>
('a->'a)->int->'a->'a
<christo_m>
like this, and i think it should be an int
<Optikal_>
Oh wait
<christo_m>
a and n are both ints
<Optikal_>
Yeah, you want n to int
<christo_m>
f is a function, or 'a
<christo_m>
unit rather
<Optikal_>
ok
<Optikal_>
I see
<Optikal_>
you have iterate_aux n x
<Optikal_>
and are calling iterate_aux n 0;;
<Optikal_>
which means that x becomes an int..
<christo_m>
x and a are synonymous i think
<christo_m>
note that in line 28, i pass f of x which is a
<christo_m>
back to the argument x in the iterate_aux function
<Optikal_>
try in iterate_aux n a
<christo_m>
wow, kk thanks it works
<christo_m>
haha
Kerris7 has joined #ocaml
Kerris7_ has joined #ocaml
Kerris7 has quit [Read error: 54 (Connection reset by peer)]
<christo_m>
Optikal_, still there man?
<christo_m>
Optikal_, im trying to fix the return types for the other fucntions because they were of 'a ref, and i dont want any references
<christo_m>
Optikal_, http://rafb.net/p/YySG3V91.html <- there's what I have so far, the second and third work fine but somethings wrong with the first (for loop iteration)
<Optikal_>
take out the ; in done;
<christo_m>
Optikal_, i have this val iterator_for : (unit -> 'a) -> int -> unit -> unit = <fun>
<christo_m>
im not returning a value i think
<christo_m>
do i need a temp value to store the contents of f a, becuase for loops dont return values or?
<Optikal_>
why are you using an iterator, i'm just curious
<christo_m>
assignment requirements.
<christo_m>
needed a for loop, non tail recursion,and tail recursion
<christo_m>
i still have to write the functions that are gonna be used by these
<Optikal_>
Ah, yeah it looks like it
<christo_m>
Optikal_, any ideas?
<olegfink>
the second function looks suspiciously similar to the third.
<christo_m>
olegfink, i hope not
<christo_m>
ones supposed to be nontail, the latter, tail
<olegfink>
how do you think a tail recursion differes from a non-tail one?
<christo_m>
well, an auxilary function being introduced
<christo_m>
id assume the two are pretty similar
<christo_m>
except you carry the value rather than return it
<christo_m>
anyway, somethings wrong with my first one :( can you help?
<olegfink>
do you think that binding x to a and not carrying f along makes a non-tail recursion tail?
<christo_m>
:(
<christo_m>
i dont know..
<christo_m>
i think using iterate_aux makes the original iterate_tail, tail
<christo_m>
im assuming its wrong though
<olegfink>
how come?
<christo_m>
i dont know
<christo_m>
i really dont man
<olegfink>
iterate_tail is not recursive at all
<olegfink>
neither is it tail recursive
<Optikal_>
not sure how to do the for loop without references
<christo_m>
hmm
<Optikal_>
did they say you can't use references?
<christo_m>
well it doesnt matter
<christo_m>
so long as the return is the same
<christo_m>
('a->'a)->int->'a->'a <- like this
<olegfink>
christo_m: read the definition of tail recursion, and then try to figure out which one function you have (tail or not) and how to write the other
<Optikal_>
I doubt the spirit of the assignment is to get the signature to match
<Optikal_>
=)
<christo_m>
it is.
<olegfink>
if you use [for] for updating a value, you obviously need to use references.