<yakischloba>
I am writing a non-blocking network i/o library. i saw some similar stuff in ocamlnet but it looked pretty foreign for an ocaml newbie
<yakischloba>
this is turning out to be very easy so far in comparison to other languages
<thelema>
enjoy writing your library - we're here because we love ocaml
<yakischloba>
seemed like a good first project. yea it has been hard to get the hang of but i am understanding it better now
<thelema>
OCaml is quite a brain exercise to work with at the beginning.
<yakischloba>
yea. looking at what i have written now though, its very straight forward
<thelema>
It helps to know what you're doing.
<yakischloba>
heh
johnnowak has joined #ocaml
<EliasAmaral>
yakischloba, have you solved your crash?
Associat0r has joined #ocaml
<yakischloba>
EliasAmaral: yes. it is hard to tell because im not really familiar with debugging ocaml yet
<EliasAmaral>
i am curious to know why caused it - a bug in your code or in ocaml's code
<yakischloba>
I was getting different failures depending on whether i used ocamlc or ocamlopt
<EliasAmaral>
hmmm. and how you solved it?
<yakischloba>
if i used ocamlopt and used gdb to debug, it was failing in the C code of the Unix module
<yakischloba>
the problem was that I was (by mistake) calling a method recursively forever
<yakischloba>
i didnt discern where exactly it was failing
<EliasAmaral>
and the program died by stack overflow?
<yakischloba>
I think i may have been running the process out of memory or something
<yakischloba>
if i used ocamlc to compile, it said stack overflow
<EliasAmaral>
ah. :)
<yakischloba>
if i used ocamlopt, i got a seg fault
<EliasAmaral>
there is no stack overflow exception with ocamlopt because it uses the OS stack
ulfdoz_ has joined #ocaml
<yakischloba>
I guess using gdb isn't the proper way to debug though, so whatever information it gave me was probably inaccurate
<EliasAmaral>
hmmmm.
<yakischloba>
regardless, i no longer have the problem since i fixed my code.
ulfdoz has quit [Read error: 60 (Operation timed out)]
ulfdoz_ is now known as ulfdoz
<EliasAmaral>
for me, networking is very foreing to my usual uses of ocaml because Unix module is so low level. but i have done it a quite times, it was a pain to make a well-behaved recv (But that was because I wasn't used to the quirks of unix api, such as capturing EINT etc)
<yakischloba>
ah. yea this is something I have worked on before a lot in C so its pretty familiar
<EliasAmaral>
this makes things easier :)
<yakischloba>
how do I make a method argument optional?
<EliasAmaral>
hmmm... i forgot the syntax, ?a maybe
<yakischloba>
ah.
<EliasAmaral>
?a=b hmm
ccasin has joined #ocaml
<EliasAmaral>
~a=b
<thelema>
EliasAmaral: ocaml should catch stack overflow even on native stack
<thelema>
let foo ?(x=4) y = x + y
<thelema>
let foo ~x ~y = x + y in foo ~y:3 ~x:5
<EliasAmaral>
thelema, so maybe he was compiling with a switch that disabled it..
<EliasAmaral>
The first case is simple: g is passed ~y and then ~x, but f expects ~x and then ~y. > labels should use row types like objects (so that you could swap ~x and ~y like you swap methods)
<EliasAmaral>
The second example is more subtle: while we intended the argument bump to be of type ?step:int -> int -> int, it is inferred as step:int -> int -> 'a. These two types being incompatible (internally normal and optional arguments are different), a type error occurs when applying bump_it to the real bump. > this is somewhat sad.
<EliasAmaral>
even if these types being different internally, they should be compatible
<thelema>
ok, is there a question.
<EliasAmaral>
if i am asking something? no, i am just trolling / blaming the language designers
<EliasAmaral>
the fact that x:int -> y:int -> int is not compatible with y:int -> x:int -> int doesn't seem great
<yakischloba>
are there any industries which seem that ocaml is used more prevalently?
<yakischloba>
i dont know much about what people write with it
<thelema>
yakischloba: There's some people building integrated web development systems in it. It's used in the theorem prover CoQ. And Jane Street and MeFi use it for financial sector operations
<thelema>
Oh yeah, merjis does something with it to do with internet advertising
<yakischloba>
i see
<yakischloba>
what are the reasons that it has not gained usage in other areas? seems to mostly be an issue of libraries and marketing towards newcomers ("its not as hard as it looks, see")
derenrich has joined #ocaml
<EliasAmaral>
it's not ocaml fault, really. other languages have a bigger community, more momentum. or.. maybe.. hmm.. that man, kerninghan (i never write his name well), the k from k&r
<EliasAmaral>
he once talked about this... ml was created at same time as c++
<EliasAmaral>
but c++ doesn't require C programmers to change their code or their programming habits
<yakischloba>
yea thats the hard part
<EliasAmaral>
ml was too revolutionary, and that's why the ml concepts are being incorporated in c++0x (such as type inference) but ml itself isn't being used very much. but..
<yakischloba>
but Erlang for instance has recently gained popularity
<EliasAmaral>
hm.
<EliasAmaral>
my bet is that microsoft will help ocaml to have a better audience
<derenrich>
??
<derenrich>
why?
<EliasAmaral>
through f#
<derenrich>
ah
<EliasAmaral>
they are selling it as something new and shiny. it's just ocaml with .net library, really
<derenrich>
minus functors and such?
<EliasAmaral>
there are no functor in f#? wow.. @_@
<EliasAmaral>
'I disagree about the useful functors, I work in a company with a huge ocaml code base and we only use them a handful of times.'
<EliasAmaral>
well, there ARE companies with huge ocaml code base, at least
<derenrich>
i think it was needed for compat with .net libs
cloudhead has quit [Client Quit]
Associat0r has quit []
<EliasAmaral>
i would prefer to receive a 'a option whenever it was possible to receive a null. that way i could see the null propagation paths in the code
<yakischloba>
i understand option now. this is what I needed when I asked to make an argument omissible
<yakischloba>
pretty cool
<EliasAmaral>
yakischloba, see my rants about type mismatch
<EliasAmaral>
but if you can live with it, yeah it's cool =)
<yakischloba>
i come from ruby where we have no such thing as a type, i dont think i will complain about mismatch yet :p
<thelema>
hmm, I might be missing some branches there...
derenrich has quit ["ChatZilla 0.9.86 [Firefox 3.5.6/20091215231400]"]
tmaedaZ is now known as tmaeda
struktured has joined #ocaml
ski_ has quit ["Lost terminal"]
ccasin has quit ["Leaving"]
<thelema>
Hmmm... I want to have a printable set. I have a printing function for my type, how can I compose the Comparable module type with the Printable module type?
<yakischloba>
these Unix things just raise Unix_error. i understand how to catch it, but if I don't then my program crashes. t he problem is that I get something like "Fatal error: exception Unix.Unix_error(59, "shutdown", "")"
<yakischloba>
the first thing just being a number instead of for instance Unix.EAGAIN or whatever
<yakischloba>
and the numbers dont seem to map to my system's errnos
<yakischloba>
ok. that's kind of annoying, for development anyway heh
<thelema>
It's just that at runtime, the names are erased. One downside of ocaml that'd be quite fixable with some extensions to the compiler
<yakischloba>
gotcha
<thelema>
Instead of this, the compiler authors leave it to macro writers to auto-create to_string conversions for Enumerations
tmaeda has quit [Read error: 60 (Operation timed out)]
tmaeda has joined #ocaml
ski_ has joined #ocaml
_unK has quit [Remote closed the connection]
bogen has quit [Read error: 60 (Operation timed out)]
bogen has joined #ocaml
bzzbzz_ has quit ["leaving"]
<EliasAmaral>
thelema, what you can do is to write a generic function that receives a print function and a set
<EliasAmaral>
and prints it
<EliasAmaral>
you can make a new functor, Printable_Set, that receives the print function as parameter
johnnowak has quit []
<EliasAmaral>
if you want to use comparable in some way, you want to print a tree maybe, as "(root left right)"
<yakischloba>
if I am catching these Unix_error's, how can i access the error from the exception if i am not matching one specifically?
ygrek has joined #ocaml
demitar has joined #ocaml
ksson has joined #ocaml
<yakischloba>
hmm
<yakischloba>
can I not pass a class through something to be instantiated?
ttamttam has joined #ocaml
<yakischloba>
let creator klass = new klass()
<yakischloba>
or soemthing?
<yakischloba>
creator(some_class)
<ksson>
no ... a class name is a type, i guess
<yakischloba>
it would surprise me if there is no way to do that
<ksson>
hmm
<ksson>
you can build a function let new_klass () = new klass
<ksson>
and write let creator f = f ()
<yakischloba>
hmm
<ksson>
now that i think of it, can you do it in another language?
<yakischloba>
do it in Ruby all the time
<yakischloba>
a class is just another object
<ksson>
ok :) i mean in any static language? :)
<yakischloba>
heh
<yakischloba>
perhaps not i guess
<yakischloba>
perhaps it is not possible
<yakischloba>
and i am stuck in dynamic land
<ksson>
:)
<ksson>
what do you need this for?
<yakischloba>
my library will provide a class to the user that they must inherit from and implement some callback virtual methods
<yakischloba>
ideally they could pass their own class to another thing of the library's to do some logic inside of it and instantiate the object from the user's class
<yakischloba>
it doesnt have to be that way, it's just nicer for the user
<ksson>
hm, and does it really help to do the "new" inside the library?
<yakischloba>
a little bit
<yakischloba>
but not enough to be worth pursuing
<ksson>
ok :)
<yakischloba>
thanks heh
<ksson>
i guess the class you inherit from does already implement some functions?
<ksson>
s/functions / methods
<yakischloba>
yes
<ksson>
ah, forget that; doesn't change anything
<yakischloba>
yea. i think its not possible for it to instantiate a class it doesnt know about yet
<ksson>
and does the user get to see the object of his class? or is it just for internal use?
<yakischloba>
they may, but it is unlikely that they will use it from outside of their callback methods
<ksson>
ok
<ksson>
i'm not that much familiar with ocaml objects
<yakischloba>
heh
<ksson>
but i guess i would do what you do with functors
<yakischloba>
it seems like a lot of people just use ocaml without the OO stuff :p
<ksson>
yeah
<ksson>
i think it's more of a habit
<ksson>
there's nothing wrong with ocaml objects
<yakischloba>
back in a few, food
<ksson>
k
<ksson>
i think, the key to objects in ocaml is that are structurally typed - the only thing that counts are the methods (and fields) it contains, not where it is inherited from
<ksson>
so you shouldn't write: let xcoord (p : point) = p#x
<ksson>
but : let xcoord p = p#x
<ksson>
so you can use that function with any object that has a method x
<ksson>
i have to go
ttamttam has quit ["Leaving."]
fx_ has joined #ocaml
<yakischloba>
k
fx_ has quit ["Leaving"]
fx_ has joined #ocaml
ygrek has quit [Remote closed the connection]
marteo has joined #ocaml
Elive_user7_fr has joined #ocaml
Elive_user7_fr has quit [Client Quit]
mjsor has joined #ocaml
mjsor has quit []
Pimm has joined #ocaml
ski_ has quit ["Lost terminal"]
ttamttam has joined #ocaml
ygrek has joined #ocaml
yakischloba has quit ["Leaving."]
ski_ has joined #ocaml
EliasAmaral has quit [Read error: 60 (Operation timed out)]
demitar has quit [Read error: 60 (Operation timed out)]
thelema has quit [Read error: 104 (Connection reset by peer)]
thelema has joined #ocaml
WuJiang has joined #ocaml
_andre has joined #ocaml
WuJiang_ has quit [Read error: 110 (Connection timed out)]
ikaros has joined #ocaml
ygrek has quit [Remote closed the connection]
<flux>
any word on the qt-caml-project, is it still alive?
onigiri_ has joined #ocaml
cloudhead has joined #ocaml
ikaros has quit ["Leave the magic to Houdini"]
ygrek has joined #ocaml
<Camarade_Tux>
flux: can you ping me about this later on today? (in a few hours)
tmaeda is now known as tmaedaZ
<Camarade_Tux>
I have a few things to fix for caravel but I'd like to take a look at it
jimmyb2187 has joined #ocaml
ikaros has joined #ocaml
cgizmo has joined #ocaml
<flux>
camarade_tux, pong
CcSsNET has quit [Client Quit]
cgizmo has quit ["Leaving."]
_unK has joined #ocaml
_p4bl0 has joined #ocaml
<_p4bl0>
hi everybody! I have a question about the ocaml compiler. Should I speak english or french on this chan?
<flux>
english.
<_p4bl0>
okay :-)
<_p4bl0>
So, I would like to have ocamlc compile a file and write the resulting .cmi and .cmo file to another directory. I can't find how to do that in the man/--help/web
<flux>
that's not possible
<flux>
so basically you either copy the sources to another directory before compiling, or move the binaries after creating the
<flux>
m
<_p4bl0>
huu... okay. That's really not handy for Makefiles
<_p4bl0>
do you know if it's a choice of the dev to not make that possible? Because I don't see how it can be difficult to do, but I really don't see what's the point of this limitation
<quelqun_dautre>
(_p4bl0: t'es francophone ?)
<flux>
_p4bl0, no idea really. perhaps it just isn't seen as that useful. I haven't missed it ;).
<_p4bl0>
flux: okay, thanks for you answers!
fission61 is now known as fission6
fission6 has left #ocaml []
demitar has joined #ocaml
_unK has quit [Remote closed the connection]
<brendan>
you could copy or symlink your source files into the buld directory. I think ocamlbuild does that.
ksson has quit [Read error: 54 (Connection reset by peer)]
joewilliams has joined #ocaml
ikaros has quit ["Leave the magic to Houdini"]
<_p4bl0>
brendan: that's not a good solution I can't easily factorise de Makefile code if i have to do that, but it's okay like that it's just that I don't like much having all .cmi and .cmo files in the src dir of my project
bogen has quit ["Leaving."]
onigiri__ has joined #ocaml
_unK has joined #ocaml
onigiri_ has quit [Read error: 60 (Operation timed out)]
yakischloba has joined #ocaml
ikaros has joined #ocaml
Submarine has joined #ocaml
Pimm has quit [Read error: 60 (Operation timed out)]
fx_ has quit [Read error: 60 (Operation timed out)]
ccasin has joined #ocaml
johnnowak has joined #ocaml
<yakischloba>
is it uncommon for people to use the OO stuff in ocaml? i havent really seen anyone using it yet :(
<thelema>
yes, the oo parts of ocaml are commonly avoided
<thelema>
Use only when necessary
<yziquel>
yakischloba: i use OO quite a lot.
<Camarade_Tux>
I'd say people often overuse OO in other languages but use it when appropriate in ocaml
<yziquel>
yziquel: i overuse it for convenience.
<yakischloba>
hmm
_p4bl0 has left #ocaml []
<yziquel>
yakischloba: you really have to think as classes as something that exists only at compile time.
<yakischloba>
why
yziquel has quit [Ping timeout: 180 seconds]
yziquel has joined #ocaml
<yziquel>
yakischloba: but if you have classes at runtime. what is their type? "class"? and then, when you instantiate an object, what is his type? as the type of an object has a meaning only at compile-time (we're not in dynamic land), instantiation cannot happen dynamically from a class that is known only dynamically.
<yziquel>
so classes are static stuff.
<yziquel>
yakischloba: and what is more perverse... they also create type abreviations.
<yziquel>
yakischloba: the type of an object is essentially a collection of its methods and their respective types.
<yziquel>
yakischloba: so you may have two classes that instantiate objects of the same types.
<yziquel>
yakischloba: you really have to think of classes as code, that is here to create objects. whereas objects have types which are not a priori related to their class.
<yziquel>
yakischloba: please tell me if i'm not clear enough.
pad has joined #ocaml
<yakischloba>
yziquel: sorry, i'll read in just a moment
<yziquel>
yakischloba: no worry.
<mfp>
"In OCaml 3.11 and later, you can call caml_page_table_add(In_static_area, start, end) to inform the run-time system that the address range [start, end) contains well-formed Caml data that polymorphic primitives can safely work on."
<mfp>
3.11 is becoming quite impressive
<thelema>
mfp: yes, nice for those who want to manage their own memory
<yakischloba>
yziquel: yea I understand those things
<yakischloba>
the type abbreviations is a bit weird
<yakischloba>
well..if i write a library using OO, will no one use it?
<yziquel>
yakischloba: it depends...
<thelema>
yakischloba: people may use it if it suits their needs. You may consider giving it a functional interface.
<mfp>
yakischloba: if it's useful, they will. See ocamlnet, for instance.
<yziquel>
yakischloba: what would it be?
<yziquel>
yakischloba: mfp is right. ocamlnet uses a lot of OO to abstract engines connecting sockets with other stuff, for instance. I use it.
<yakischloba>
my library is similar in purpose to ocamlnet
<yakischloba>
non-blocking/evented network i/o
<flux>
yakischloba, have you looked at Lwt?
<mfp>
yakischloba: it holds in a tautological way, but it here goes: if you use OO when appropriate, ppl will have no objection to it.
<mfp>
yakischloba: something like equeue or Lwt?
<yziquel>
yakischloba: Lwt is really cool for this kind of thing.
<yakischloba>
yes like equeue. equeue simply provides an event loop right?
<mfp>
generic event queues + an implementation for file descriptor events
_andre has quit ["leaving"]
<yakischloba>
my library handles all of the i/o
<yakischloba>
it will read data from sockets when it is available and call your callback with it
<yakischloba>
and you hand it data to send, and it will do so whenever it is able to
<yakischloba>
EventMachine is the ruby library I am modeling it on
<thelema>
yakischloba: since ocaml is functional, callbacks are usually really easy. You could use (string -> unit) functions for ease of use
<yakischloba>
yea
<thelema>
or use (string -> ~pos:int -> ~len:int -> unit) functions for speed
<thelema>
(to avoid copying your data one more time)
<yziquel>
yakischloba: look at lwt for doing concurrent stuff. As for callbacks, have a look at the React module.
<yakischloba>
hmm
<yakischloba>
well i am having fun writing this anyway, it is the best way to learn for me
<yziquel>
yakischloba: i've had a similar thing to do. a scheduler. works out quite nicely.
Pimm has joined #ocaml
Amorphous has quit [Read error: 104 (Connection reset by peer)]
<joewilliams>
yakischloba: i was just about tell you about lwt
<yakischloba>
yea lwt looks cool
<joewilliams>
found it searching for an amqp lib for ocaml, one doesnt seem to exist :(
<yakischloba>
lwt basically looks like neverblock
<yakischloba>
or can provide the same concept
<joewilliams>
ah, i recall neverblock, its ruby fibers with some sugar right?
<yakischloba>
yea. yields fibers when waiting for io
<yakischloba>
i recall that at some point it was not able to infer what it should be. perhaps i was doing something else wrong
<joewilliams>
thelema: im new to ocaml too (but know erlang pretty well) the is that just a list comprehension?
<thelema>
joewilliams: it's equivalent to a list comprehension, but it's just calling a higher order function.
<joewilliams>
got it, thanks
<thelema>
List.iter takes two parameters, a function and a list, and calls that function on each element of the list.
<joewilliams>
yup, thats identical to list:map/2 in erlang :)
Dodek has quit [Read error: 113 (No route to host)]
<thelema>
almost - iter doesn't construct a result list, it takes a function that returns unit, and returns unit itself
<thelema>
List.map is the ocaml equivalent of what you're thinking of.
<joewilliams>
ok cool
<yziquel>
yakischloba: "not being able to infer what it should be" it's a problem with polymorphism of methods in classes.
<yakischloba>
ok
<yziquel>
when you have a 'a in a method, it expects to find a ['a] at the level of the class declaration. If it does not (which means that the class is not polymorphic), it complains because it gets confused: is it the class that is polymorphic, or the method that is polymorphic?
Dodek has joined #ocaml
<yziquel>
yakischloba: for methods, you can use a type like 'a. ('a -> 'a). This way the 'a is bound the method and not to class: class is not polymorphic, but the method is.