cjeris changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/
bluestorm_ has quit [Remote closed the connection]
cjeris has quit [Read error: 104 (Connection reset by peer)]
pantsd has joined #ocaml
shawn_ has quit ["This computer has gone to sleep"]
malc_ has quit ["leaving"]
postalchris has joined #ocaml
pantsd has quit [Read error: 110 (Connection timed out)]
benny_ has joined #ocaml
benny has quit [Read error: 110 (Connection timed out)]
_blackdog has quit [Remote closed the connection]
shawn_ has joined #ocaml
shawn_ has quit [Read error: 60 (Operation timed out)]
postalchris has quit [Read error: 110 (Connection timed out)]
mikeX has quit ["leaving"]
G has joined #ocaml
G_ has quit [Connection timed out]
lasts has quit [Read error: 60 (Operation timed out)]
jeberle has joined #ocaml
jeberle has left #ocaml []
beschmi has joined #ocaml
pstickne_ has joined #ocaml
pstickne_ has quit [Remote closed the connection]
pstickne_ has joined #ocaml
pantsd has joined #ocaml
G_ has joined #ocaml
G has quit [Read error: 110 (Connection timed out)]
Submarine has quit ["Leaving"]
love-pingoo has joined #ocaml
G_ is now known as G
ulfdoz_ is now known as ulfdoz
lucca has quit ["yarr"]
love-pingoo has quit ["Leaving"]
kelaouchi has quit ["leaving"]
kelaouchi has joined #ocaml
LeCamarade has joined #ocaml
kelaouch1 has joined #ocaml
beschmi has quit [Read error: 104 (Connection reset by peer)]
beschmi has joined #ocaml
kelaouchi has quit [Read error: 110 (Connection timed out)]
love-pingoo has joined #ocaml
Sparkles has joined #ocaml
love-pingoo has quit ["Leaving"]
LeCamarade has quit ["ExitFailure 27"]
_blackdog has joined #ocaml
mikeX has joined #ocaml
Sparkles has quit []
LeCamarade has joined #ocaml
<LeCamarade>
Anybody here knows how to add dynlinked modules' functions to be callable?
<LeCamarade>
After Dynlink.loadfile, I can't call the funcs. How can I map 'em into the func table?
<flux>
the idea is that the loaded file calls some module you've linked it during compile time, to register its interface
<LeCamarade>
So, I don't load a file to use the funcs therein?
<flux>
a module such as sig type somethingdoer = { do_something : unit -> unit } val register : somethingdoer -> unit end
<LeCamarade>
s/file/module/
<flux>
well you couldn't possibly check such code in a static fashion
<LeCamarade>
I see. But ...
<flux>
infact objects might have some nice usage here
<LeCamarade>
What, then, is the utility of module-loading?
<flux>
to implement 'plugin'-like features
<LeCamarade>
Yeah, but how can a plugin work, if I can't call funcs in a module?
<flux>
on OO terms the loaded file would register itself with a factory
<flux>
thus it's the loaded module that calls the main code, not the other way around
<flux>
after registering itself the main module has references to the module
<LeCamarade>
Hmm ...
<flux>
and thus can call code from it
* LeCamarade
goes off to try that.
<LeCamarade>
But how can I compile something that is only working on the hope of a module that will be loaded? Do you have a very short example?
<flux>
the simplest version would be something like: module Interface = struct let do_something : (int -> unit) ref = ref (fun _ -> failwith "not implemented") end
<LeCamarade>
Like, in main.ml, can I refer to func that are in willbeloaded.cmo?
<flux>
and then the loaded module would do Interface.do_something := (fun i -> Printf.printf "i = %d\n%!" i)
lasts has joined #ocaml
<flux>
after loading the module other functions would be able to do (!Interface.do_something) 42
<flux>
(you would place that module Interface into file interface.ml without the module Interface = struct end -wrapper)
<flux>
the loaded module is evaluated when you load it, one time
<flux>
so it can call functions after it's been loaded
<LeCamarade>
Has anybody used these successfully?
<LeCamarade>
Even !successfully?
<LeCamarade>
:oD
<flux>
I apparently don't have any sources that use it.. I think I've played with it..
<flux>
ah, I grepped for Dynload, not Dynlink
<flux>
my still-not-working ocaml-plugin for irssi uses them
<LeCamarade>
I'm working on desertbot.
<LeCamarade>
The #ocaml bot.
<LeCamarade>
:oD
<flux>
it might've worked..
<LeCamarade>
Progressed lots, but I want her to compete well with lambdabot of #haskell. I need to be loading modules and stuff, so it can be extended by far-flung people. Just an exercise in OCaml.
<flux>
I think an interesting approach could be implementing the modules as external binaries, and provide a library that gives you the protocol in an easy-to-use fashion
<flux>
after all, with irc bots, it's hardly about performance
<flux>
and it would provide very good robustness
<LeCamarade>
flux: That's exactly where I am, right now.
<LeCamarade>
For one, I prefer binaries to provide extension - so I write my extensions in anything that works, .sh included.
<LeCamarade>
s/binaries/exes/
<LeCamarade>
I have a small shell-like thing whose job is to extend the shell that way. I am going to do it that way, alright. If I ever get to need module loading, I'll include it.
<mrvn>
flux: wouldn't it be better to rewrite irssi in ocaml?
<flux>
mrvn, which do you think is a smaller task?
<flux>
mrvn, and thus, more likely to happen..
<mrvn>
which do you think is the better task?
<flux>
writing an ocaml-module for irssi.
<mrvn>
I would love to have a few networking modules with a good interface.
<flux>
code reuse, man!
<mrvn>
Starting with http.
<flux>
mrvn, ocamlnet?
<mrvn>
either blocking or very very ugly non-blocking interface
<flux>
I've only used its convenience -module
<flux>
so I don't know about its non-blocking http interface, if there is one
<flux>
the convenience-module was a breeze to use, though
<flux>
basically Http.get "http://.." or .post ".." "data"
<flux>
I'm thinking a genuinely nice-to-use non-blocking interface is difficult to do without resorting to cps or monads..
<flux>
oh, or continuations, which we don't have (atleast yet)
Sparkles has joined #ocaml
<mrvn>
cps is continuations
<flux>
well, I mean the continuations you use with call/cc
ita is now known as ita|aw
<LeCamarade>
flux: Is there a conf module in OCaml? As in, one to help deal with conf files (even if it enforces a conf philosophy)? Not XML.
<flux>
not in, but I think there are init module written for ocaml
<flux>
check out caml humps (google)
<LeCamarade>
flux: I guess the same goes for XML, no? I have the humps on my feeds.
<flux>
yes
<flux>
I've used xml-light
<flux>
but cps can really be nice sometimes.. let client_handler () = let rec aux () = get_line fd @@ fun line -> respond fd "hello %s\n" line; get_line fd @@ fun line -> respond fd "%s\n" line; aux () in aux ()
<flux>
whereas 'usually' one would use threads or an explicit state machine..
* flux
still gets excited about functional programming :)
<mrvn>
threads suck
<mrvn>
You can't have 10k threads, one per socket.
ygrek has joined #ocaml
cjeris has joined #ocaml
<flux>
depends on what you think by thread
<flux>
I think the erlang guys would disagree with you
<jlouis>
the erlang guys call a "thread" a "process" (because it is isolated: You can only send and receive messages between processes).
<jlouis>
and 10k erlang processes is no problem. One is less than 400 bytes
tree has joined #ocaml
<ita|aw>
LeCamarade: use json
pstickne_ has quit [Remote closed the connection]
pango_ has quit [Remote closed the connection]
pango_ has joined #ocaml
<mrvn>
In AmigaOS a process is a task with some extras like a controling terminal.
<mrvn>
So even more heavy than normal tasks
bluestorm has joined #ocaml
Sparkles has quit []
<ita|aw>
bluestorm: hey
ita|aw is now known as ita
* ita
slaps bluestorm with a large vt100 terminal
<bluestorm>
twas about lasts
<bluestorm>
did he contact you ?
<ita>
bluestorm: yes, but he has not told me yet what it is about
smimou has joined #ocaml
<bluestorm>
maybe he's a little bit shy
ygrek has quit [Remote closed the connection]
ygrek has joined #ocaml
Demitar has quit [Read error: 113 (No route to host)]
<LeCamarade>
But does anyone notice how severly lacking the basic libraries are, in OCaml? I mean, compared with Haskell, for example.
<LeCamarade>
There is no Array.head, tail, filter.
<LeCamarade>
And String is almost empty.
<LeCamarade>
No equivalent for cons, cdr, car for string, array and list. That is not amusing.
<LeCamarade>
:o(
<hcarty>
LeCamarade: There's always ExtLib
love-pingoo has joined #ocaml
<ita>
LeCamarade: useless
<bluestorm>
ita: LeCamarade
<bluestorm>
what would you use Array.tail for ?
<bluestorm>
black magic ?
<bluestorm>
Array.to_list should be enough for this purpose, i think
<bluestorm>
String are a not as elegant as in Haskell, but there is a huge efficiency gain
<bluestorm>
(no everyone need to use string as list)
<bluestorm>
+t
<LeCamarade>
bluestorm: Isn't there a performance hit in using lists?
<bluestorm>
LeCamarade: i personally feel a lack of option primitives ('a option is the Maybe a)
<bluestorm>
but Array.tail really seems useless
<mrvn>
There is String.sub
<LeCamarade>
I want it on Arrays and pre-packaged, so that I know it is there (and it works in the REPL).
<mrvn>
Also Array.init and Array.sub
<LeCamarade>
mrvn: I iterate from one end to the other, and what pattern matching does for me String.tail should ease.
<LeCamarade>
Array.init ... hmm
<mrvn>
What is String.tail supposed to mean? All but the first char?
* LeCamarade
is still rather fresh, and may now have to refactor some code.
pango_ has quit [Remote closed the connection]
* LeCamarade
feels a bit like a dork ...
<mrvn>
Note that string and array are imperative while lists are functional. that completly changes the interface.
<bluestorm>
i don't think Array is the right datastructure to use tail on
<mrvn>
What I'm missing is String.explode : string -> char list and String.implode : char list -> string
<bluestorm>
if you feel a need of beautiful recursion and filter and so on
<mrvn>
LeCamarade: What is Array.tail supposed to mean?
<LeCamarade>
Not that it matters, but ... I think strings and arrays aren't lists for a reason.
<mrvn>
LeCamarade: O(1) random access.
<LeCamarade>
mrvn: The whole array without the first elem.
<mrvn>
LeCamarade: Array.sub
<mrvn>
And that is horribly inefficient as it copies the array.
<bluestorm>
LeCamarade: Array.tail would perform a lot worse than with a list
<bluestorm>
Array.filter too
<mrvn>
filter alway copies
<mrvn>
But you would have to first count the number of elements, then create the String or Array and then filter again.
<LeCamarade>
Oh, I see! But I need to filter!
<mrvn>
or resize the string/array every time you add an element. Both would seriously suck
* LeCamarade
likes to kick it in one line, as they say.
<LeCamarade>
mrvn: I understand.
<bluestorm>
LeCamarade:
<bluestorm>
why do you have an array if you need to filter ?
<LeCamarade>
But there is no way around it, if I have to filter, right? I have to do it.
<bluestorm>
let Array.filter p tab = Array.of_list (List.filter p (Array.to_list tab))
<mrvn>
let filter_array f = Array.fold_left (fun (yes, no) x -> if f x then (x::yes, no) else (yes, x::no)) ([], [])
<bluestorm>
:p
<LeCamarade>
bluestorm: I should always convert to a list and then filter and then back to array? Okay.
<mrvn>
+ List.rev if the order should be preserved
<bluestorm>
LeCamarade: i think the best idea would be to convert to a list, and then stay with a list
<bluestorm>
because if you feel a need of tail and filter of so on
<bluestorm>
arrays certainly aren't the adequate data structure anymore
<bluestorm>
you might have used random access at the beginning of your code, but if you don't use it, and use filter and tail, you should convert you array to a list and keep it
<mrvn>
Head and tail could work with Bigarrays since you can slice them.
<LeCamarade>
bluestorm: I am afraid I'll always feel that need - so when should arrays be useful? Non-mutable stuff (almost)? Like ... directory contents, et cetera?
<bluestorm>
random access
<LeCamarade>
bluestorm: Understood.
<LeCamarade>
You should bear with me - I am a bit brain-washed from the Other Language. I need some re-adjustments.
<bluestorm>
:p
<mrvn>
What I don't get is why String isn't just a char array.
<mrvn>
There is no need for the special type imho.
<bluestorm>
maybe there are some efficiency issues again
<mrvn>
char array uses 4/8 bytes per char I think but that is the compilers fault.
<bluestorm>
(of course you could decide to unbox char, but then you may have some encoding problem and so on)
<mrvn>
bluestorm: the compiler could store a char array the same way it stores string. problem solved.
<bluestorm>
hm
<mrvn>
Both have random access, most functions are the same.
<bluestorm>
yes, you're right
<mrvn>
Only String.create would be chalenging.
<mrvn>
Array.create would be difficult for non char arrays and you can't just have a function for one subtype.
<bluestorm>
but String.create isn't the more useful function
<bluestorm>
hum
<bluestorm>
another problem is that it could give bad ideas about the ^ use on arrays
<mrvn>
If you use strings for buffered I/O or I/O in general it can save a lot of time.
<bluestorm>
String.create instead of String.make ... '\0' ?
<mrvn>
bluestorm: ^ on string/array is just as bad as @ on lists
<bluestorm>
yes but ^ seems acceptable on arrays when you're in a hurry
<bluestorm>
h
<bluestorm>
hm
<bluestorm>
on stings
<mrvn>
let s = String.create bufsize in read s 0 bufsize
<bluestorm>
hm
<bluestorm>
btw
<mrvn>
bluestorm: I use ^ on actual text strings often. They tend to be small so it doesn't matter.
<bluestorm>
do you know if Printf.sprintf "(%s)" is more efficient than (fun s -> "(" ^ s ^ ")") ?
<mrvn>
like let name = path ^ filename
<bluestorm>
hm
<bluestorm>
Filename.concat would be better ^^
<mrvn>
I would hope sprintf first counts the length and then allocates a single string.
<LeCamarade>
Guys, when I'm done with my bot (gimme a week max) you'll be able to run snippets here. It's taking commands, now. Just no modules. :oD
<mrvn>
I would hope String.concat also does first count. Never checked if they do.
<bluestorm>
LeCamarade: you're doing a ocaml lambdabot ?
<LeCamarade>
bluestorm: Aye.
<bluestorm>
:p
<LeCamarade>
Should rock more than lambdabot. Well, at least as good.
<bluestorm>
hm
<bluestorm>
not an easy task
<mrvn>
On thing sucks with string in ocaml on 32bit cpus. Sys.max_string_length is only 16MB.
<LeCamarade>
desertbot is the name. Unless, of course, someone has a more-suiting one.
<bluestorm>
but when you'll have something usable LeCamarade i'd be interested to see it
<bluestorm>
hm
<bluestorm>
LeCamarade:
<bluestorm>
desertbot as Desert Spring, the never-finished ocaml OS ? ^^
<LeCamarade>
bluestorm: :oD
<mrvn>
bluestorm: Did they use a subset of ocaml that didn't need a GC?
<LeCamarade>
bluestorm: More like a bot for the desert where we find the Caml.
<bluestorm>
hm
<bluestorm>
mrvn: you should have a look yourself
<bluestorm>
there was a second aborted os project, actually
<bluestorm>
hm
<bluestorm>
Flink or something like that
love-pingoo has quit ["Connection reset by pear"]
<mrvn>
bluestorm: Looks like i386 only.
<ita>
bah, why programming an os anyway
<ita>
there are far more interesting things to do
<mrvn>
ita: Because it is fun
<ita>
lack of creativity
<mrvn>
The tree is planted, the child if forked and the editor is written. What is there left to do?
<ita>
and if you are feeling bored there is always the list of millenium prizes
<ita>
so something useful, create something new instead of polluting the internet with useless junk :-)
<LeCamarade>
mrvn: Maybe we should stretch what an OS does. Maybe we aim too low. Maybe all these Linux/Mac/Win are just ashaming, primitive knock-offs of the punch-card.
<bluestorm>
Plan9 is there anyway :-°
<bluestorm>
(and Hurd/coyotos is coming)
<mrvn>
LeCamarade: Linux is a kernel, not an OS
<mrvn>
hurd has been coming for what now, 10 years?
<bluestorm>
more :)
<mrvn>
Is hurd l4 based now instead of mach?
<bluestorm>
i'd say 20
<LeCamarade>
mrvn: s/Linux/Ubuntu/gi
<bluestorm>
mrvn: both trees are active, i think
<mrvn>
LeCamarade: Debian GNU/linux.
<LeCamarade>
mrvn: HURD is probably the best advancement there. At least better than Linux.
<bluestorm>
Linux has evolved a lot
<mrvn>
LeCamarade: no. Hurd is pretty crap. L4 is the advancement
<LeCamarade>
mrvn: I'm on Deb, too. :oD
<bluestorm>
i think it's easier to say "bah, how ugly" than to actually code something as good
<ita>
debian sucks
<LeCamarade>
Hurd was implementing L4 ideas.
<mrvn>
ita: right, it doesn't crawl at all :)
<ita>
btw, writing ugly code is much more difficult than it looks
<LeCamarade>
ita: What do you use? And how did you install OCaml? For me it was apt-get install ocaml. That.
<bluestorm>
ita: :D
<LeCamarade>
ita: More difficult in FP. In Java, no options.
<ita>
LeCamarade: did that too, just the X server that wont work on my box
<bluestorm>
but actually LeCamarade
<ita>
LeCamarade: well, actually it is easier in FP (a few fold_left and map and you are lost)
<ita>
and the type inference makes it easy
<mrvn>
ita: that just takes practice
<ita>
mrvn: id say it is np-hard (coloring problem)
<bluestorm>
yum install ocaml, emerge -iv ocaml, pacman -S ocaml, urpmi ocaml and sudo aptitude install ocaml are not so difficult too
<ita>
i prefer make world
<mrvn>
remember the good old days? Open magazine, start typing.
<LeCamarade>
ita: FP stopped me from writing crappy code, even when I wanted to. I was working on C# today, and I broke up some zillion lines into recursive calls, and ended up with 5 times less code. With cleaner code. FP matters.
<ita>
mrvn: internet with 2kb/second .. :-)
<mrvn>
My C64 didn't have an accoustic coppler.
<LeCamarade>
bluestorm: Until they remove the libs they depend on.
<ita>
LeCamarade: let's say fp enables both uglier and cleaner code :-)
<ita>
LeCamarade: have you seen the example with iter and fold in the caml docu ?
* LeCamarade
is a new-gen coder.
<mrvn>
And I never did build myself a dialing robot for those analog wheel phones (not touchpad ones).
<LeCamarade>
ita: Not uglier. Very, very dense, yeah, very much. Very, very much. But it is always pretty. Like a painting of a battle field.
<mrvn>
Anyway, FP is a state of mind mostly. you can programm functional in C if you want.
<ita>
LeCamarade: let iter f x l = List.fold_right (List.fold_left f) [List.map x l] l;;
<ita>
mrvn: give me tail recursion in C
pango_ has joined #ocaml
<LeCamarade>
mrvn: That is called having enough rope to hang yourself with. No TCO in C (or Java or C#). But ... you can recurse if you want. C, yes. Java/C# um ... yes.
<mrvn>
ita: get a good gcc or use goto
<ita>
mrvn: compiler does not help for algorithmic complexity, does it ?
<mrvn>
ita: no. but it can detect tail recursion
<ita>
which gcc ?
<LeCamarade>
ita: Nice link.
<mrvn>
The actual challenging part of functional programming in C is specifying higher order functions.
<ita>
LeCamarade: can you understand the code ?
<ita>
mrvn: bah, functors :-)
<ita>
(pointers to functions)
<LeCamarade>
I love space-dependent syntaces. My ideal language would sneak spaces into every spot that has ;,: in OCaml.
<flux>
mrvn, if strings were really special char list with optimized layout, functions with 'a list would need to know more exactly what kind of list they're dealing with
<flux>
mrvn, or alternatively such functions would need to be compiled twice
<ita>
LeCamarade: look at the iter thing i aml talking about
<mrvn>
ita: function tables or tamples.
<bluestorm>
(a thesis about functional code compilation using gcc)
<mrvn>
templates
<flux>
mrvn, and also, what would the optimized char list look like after you construct the string one character at a time, ie. with a fold or map
<bluestorm>
LeCamarade:
<mrvn>
flux: char arrays, not list.
<bluestorm>
ocaml doesn't need ;;
<bluestorm>
but you have ocaml+twt if you want
<bluestorm>
(it does more than removing ;;)
<ita>
ocaml+twt rulez
<bluestorm>
i'm waiting for the camlp4 twt extension :-°
<flux>
mrvn, oh, well that would be possible.. I can't see why the String-module couldn't be implemented with plain char array
<mrvn>
flux: but I guess you are right. If char array uses unboxed chars then you have to compile 'a array functions twice.
<ita>
bluestorm: it does! it is possible to chain the preprocessor
<bluestorm>
i mean
<ita>
bluestorm: and i have a trick for using the # as a comment
<bluestorm>
having twt implemented as a campl4 extension
<LeCamarade>
I'm going to read this whole thing when my eyes aren't crying. (It's night over here, and I want to add a few lines to desertbot.)
<bluestorm>
but maybe it would be even uglier than now :P
<mrvn>
ita: great. so you can write code that is both bash and ocaml in one. :)
<flux>
mrvn, that's even more prohibitive if there are more than 1 'a array arguments
<ita>
LeCamarade: children must go to bed :-)
<ita>
mrvn: haha
<flux>
mrvn, 2^n versions would be required..
* ita
goes out for a walk
ita is now known as ita|away
<LeCamarade>
ita|away: Me? Not a kid ... :o)
<mrvn>
flux: except that all access to array elements is through the Array module and only that has to care about the array layout.
<mrvn>
flux: So you only need the Array functions twice.
<flux>
mrvn, I would imagine foo.[n] being inlined.. no?
<flux>
.(n) even
<mrvn>
flux: optimization of Array.get
<flux>
mrvn, if the check is would be done for all such accesses, it would be even slower - atleast without smart optimizations
<mrvn>
flux: which is probably the reason there is String
<flux>
but such assembly level optimizations would still need to generate twice the code, assuming the accesses would be inlined
<mrvn>
But they could have the same amount of functions at least. Like why is there no String.to_list?
<flux>
I think there is a consensus that the ocaml standard library is lacking :)
<mrvn>
true.
<tsuyoshi>
doesn't extlib have string.to_list
<mrvn>
Another function I missed lately: String.split : char -> string -> string list. The opposite of concat.
<mrvn>
or string -> string -> string list
<hcarty>
mrvn: Doesn't Str have something like that? Is Str.split what you want?
<tsuyoshi>
ok extlib definitely has a string split
<tsuyoshi>
go install extlib right now, it has lots of nice stuff
<flux>
also, I can understand why Hashtbl has the t argument as the first parameter, while Map has it as the last parameter (some handwaving reason of one being imperative and the other being functional)..
<flux>
but why does Queue also have it as the last parameter
<flux>
that's obviously something that cannot be changed anymore, though :)
<flux>
((and while I'm on it: functional versions of such data structures would be a nice addition..))
tree has quit [Nick collision from services.]
tree has joined #ocaml
tree has quit [Nick collision from services.]
tree_ has joined #ocaml
ygrek has quit []
the_dormant has joined #ocaml
the_dormant has quit []
lasts has quit []
ita|away is now known as ita
<ita>
first rule of optimization: do not optimize
<flux>
I would add the word 'first' there
<ita>
second rule of optimization: do not optimize after either