<pango>
something like that, but for your expression datatype instead of lists
<pango>
actually you could do without creating a HoF, but you'll probably find it handy to have it later
<asmanian>
ok, thank you for the quick answer :-)
<pango>
what you strictly need is a recursive function that takes an existing set, an expression, and that returns a set with the original set, and the new variables found in the expression; Creating a HoF first will just factorize the expression traversal for later
<tld>
pango, thanks. :)
<asmanian>
hm
<asmanian>
whouldnt that create a new set in every step?
<asmanian>
Maybe I just need something like map but without return value
<pango>
well, if you have problems writing the HoF version, you can start with the direct approach first, and generalize your code later...
<pango>
tld: actually I thought I'd found something better maintained :/
<pango>
asmanian: sets are persistant, yes
<pango>
asmanian: but that's not as bad as you think; sets are immutable recursive datastructures, so they'll share most of their contents
<pango>
asmanian: most like let l2 = "hello" :: l1 will *not* copy l1 to create l2, just reuse the existing list
<tld>
pango, no big worry
<pango>
like iter then ?
<pango>
s/found/find/
<asmanian>
When creating a folding HoF Im actually running into the problem that I whould need 2 LoFs as parameter in the general case. In this example one LoF variable_name -> set -> set and another one set -> set -> set
<tld>
hmm, one more thing... I have a project where I mmap() a file in multilpe processes, and have datastructures based on relative pointers within that. Would I be able to use that method with OCaml?
<asmanian>
ah okay I already was afraid of spamming my memory and cpu
<pango>
tld: Bigarray provides file mmap()ing; I think I've seen mmap() facilities in 3rd party modules too (CDK ?) but maybe Bigarray will be just fine
<tld>
thanks. :)
<asmanian>
ah I think im getting it...
<pango>
asmanian: I don't think providing 2 functional arguments is a big issue really... For larger numbers, or to avoid mistakes, that could be solved by the use of functors, but that's another story :)
<pango>
that is, parametrize your function with a module (that will contain all those functions)
<pango>
somewhat like templates, but relying on polymorphism, rather than preprocessing
<pango>
asmanian: mmh actually, if the set is correctly threaded, you won't need to use unions at all
<asmanian>
hm
<pango>
when handling an expression with several subexpressions, just use your function recursively, each time using the previous set as new starting value
<asmanian>
Im not sure how to do that actually
<pango>
let expression_fold fadd acc e =
<pango>
let rec fold acc = function
<pango>
| Var v -> fadd v acc
<pango>
| Plus e1 e2 -> fold (fold acc e2) e1
<pango>
| ...
<pango>
in fold acc e
<asmanian>
because I would recurse in tree order
<asmanian>
hm
<pango>
(mmh probably Plus (e1, e2) or something; didn't try compiling this code)
<pango>
I used a nested function (fold) to avoid repeating fadd argument all over the place
<asmanian>
Ill try that
<asmanian>
Maybe my fault was not to think about the possibility of a nested function
<asmanian>
what is the match in your example against?
<pango>
against the expression
<asmanian>
ah
<asmanian>
makes sense
<pango>
I used the 'function' keyword, but I could have written like let rec fold acc e = match e with ...
<pango>
it's equivalent
<asmanian>
I see I didnt know 'function'
<pango>
it does pattern matching on an extra unnamed argument
Demitar has quit [Remote closed the connection]
<pango>
I usually avoid using it because it often obscure the meaning of code (in some cases it's nice, though)
<asmanian>
The plus line with the nested fold is actually what my mind wasnt able to invent
<pango>
here I used it to avoid pasting one additional line ;) But in my own code, I think I'd go for the let rec fold acc e = ... match e with
<asmanian>
It works :-) thanks a lot
<pango>
np
<asmanian>
it seems already to me that functional programming requires a different way of thinking than imperative does
malc_ has joined #ocaml
<asmanian>
but that way feels good
<pango>
yes, both paradigms are useful; what's great with multiparadigm languages is that you have the choice :)
<asmanian>
yes thats cool. But I feel ocaml is pushing a bit into functional direction
<asmanian>
because the loops are very primitive
<asmanian>
at least the tutorial states so
<pango>
well, there's nothing like break, continue, etc. You could emulate them with exceptions, but that's a bit awkward
mindCrime_ has quit [Read error: 113 (No route to host)]
<asmanian>
And I find it strange that these records (or was it structs?) exist, as the class/object way is said to provide the same things but more powerful?
<pango>
OO is there for cases when OO makes sense
<pango>
if you just need records, you have records :)
<asmanian>
well, but if i later on discover it whould be nice to extend my things i have to rewrite them to oo, so why not just use *one* syntax? nobody forces you to use inheritance etc just because you use objects
<llama32>
i'd like to implement an ml-like type system... i've been reading up on the HM algorithm, but i'm not really grasping it... anyone know of some small type inferer sources out there - or some good papers/articles/.. about it?
<pango>
asmanian: the drawback is that if you, say, make a typo in some name, the compiler will not notice it immediately
<asmanian>
hm okay, so one could say structs have the advantage of being more strict in use
<asmanian>
I am also not sure about what you said: where *is* the place for OO in ocaml? I mean the standard containers do not seem to have an OO-interface...
<pango>
I suppose there's a small additional memory footprint too (probably just one word per object ?)
<asmanian>
is every larger ocaml project in OO? Or is it typically structured through models
<asmanian>
?
<pango>
asmanian: many programs don't seem to use OO at all
<malc_>
asmanian: Jacques Garrigue had OO interface to standard containers
<malc_>
but (i guess) he made them just for the heck of it
ikaros has quit ["Leaving"]
ikaros has joined #ocaml
llama32 has quit [Read error: 145 (Connection timed out)]
asmanian has quit ["Verlassend"]
alexaandru has joined #ocaml
pango has quit ["bbl"]
llama32 has joined #ocaml
<llama32>
would it be possible to write an ml implementation that - while still having pattern matching, didn't in fact do type inference, but rather was just dynamically typed [not to take advantage of dynamic typing - just out of laziness to write a type inferer to begin with?]?
<mattam>
"everything is possible"
tld has quit [Remote closed the connection]
* llama32
tests mattam's theory by stealing his wallet, car and the deeds to his house over irc
<mattam>
luckily i have no car
tld has joined #ocaml
<mattam>
i would'nt be interesting to do it though
<mattam>
s/i /it /
<llama32>
im writing a toy lisp implementation, and i was going to use it to experiment with an ml type system in a more lisp-like language... im too un-educated to understand type inference algorithms right now however :)
<llama32>
being 2:20am here doesn't help either
<mellum>
llama32: that would easily be possible, except that it would not allow to cach type errors at compile time
mindCrime__ has joined #ocaml
mindCrime__ is now known as mindCrime_
mindCrime_ has quit [Remote closed the connection]
llama32 has left #ocaml []
jajs has joined #ocaml
delamarche has quit []
pango has joined #ocaml
Jessehk has joined #ocaml
mbernade has joined #ocaml
mbernade has quit [Client Quit]
<Jessehk>
If I've created a library file (*.cma), how do I link it with an implementation file?
<Jessehk>
just "ocamlc *.cma *.ml -o main" ?
<pingoo>
Jessehk: yup
<Jessehk>
great, thanks.
pingoo has quit ["Leaving"]
mikeX has joined #ocaml
velco has quit ["Ex-Chat"]
buluca has joined #ocaml
ChoJin has joined #ocaml
_JusSx_ has quit [Read error: 110 (Connection timed out)]
ChoJin has quit ["This computer has gone to sleep"]
Jessehk has quit ["Ex-Chat"]
stevan has quit ["Leaving"]
Smerdyakov has joined #ocaml
danly has joined #ocaml
stevan has joined #ocaml
_JusSx_ has joined #ocaml
malc__ has joined #ocaml
_velco has quit [Remote closed the connection]
malc_ has quit [Read error: 110 (Connection timed out)]
malc__ has quit ["leaving"]
gunark has joined #ocaml
<gunark>
guys i need some advice on the most efficient way to read data from stdin into a Bigarray
<gunark>
basically, I was hoping to use something like Array1.map_file to map the stdin file descriptor
<gunark>
that way I'd have it available as a Bigarray
<gunark>
but i can't figure out a way to do that properly, since data from stdin is streaming...
<gunark>
so basically now I'm stuck doing Unix.read into a string buffer
<gunark>
and then copying the chars from that one by one into the array
<gunark>
to make things worse, I need 16 bit ints, but the data that I get form stdin this way is 8 bit chars/ints, so I have to do conversion on every pair of strings...
<gunark>
it's all kind of ugly and slow
<gunark>
any ideas?
<gunark>
every pair of chars --> int16's, i mean
<tsuyoshi>
there's no Bigarray function for reading from a file?
<gunark>
well, there is map_file, but i don't think that will work for a streaming/fifo file descriptor like stdin
<tsuyoshi>
ok
<tsuyoshi>
I see two options
<tsuyoshi>
you can either fill the array manually
<gunark>
yeah that's what i'm doing
<tsuyoshi>
or write a function in c to fill the array
<gunark>
but it's nasty
<tsuyoshi>
gunark: how is it nasty? too slow?
<gunark>
ah i was afraid of the latter :)
<gunark>
yeah... i read two char's at a time, convert to 16 bit int, put into array...
<tsuyoshi>
I mean, you've actually run the code and it's too slow for you?
<tsuyoshi>
you don't necessarily have to read only two chars at a time
<gunark>
this is supposed to be a real-time app, and i have a feeling this will turn into the big bottleneck
<gunark>
right, i can read the whole buffer
<tsuyoshi>
you can read a big string and then just convert 2 chars at a time
<tsuyoshi>
but still
<tsuyoshi>
if you do it in c you can skip the conversion step entirely
<pango>
past some size, it may prove slower
<gunark>
yeah i might even be able to use a 8 bit integer array and then map that same array again as 16 bit... but still
<tsuyoshi>
assuming the endian lines up correctly
<pango>
in fact, since you read from a stream, it *may* be slower
<gunark>
hm well looking at the IO api, this might help a bit
<gunark>
since i can read directly as unsigned 16 bit int from the stream
<pango>
gunark: that page comes from the extlib library documentation, so it requires extlib
<gunark>
right, taht's why i didn't see it in stdlib
joshcryer has joined #ocaml
<gunark>
but you're saying that at the end of the day, my best bet is to generate my array in C, and map that directly from ocaml
<gunark>
in terms of performance
<pango>
not sure it will make any difference
<gunark>
sooner or later I will probably have to go this way, since the app will be feeding in data from C-based apps and libraries
<pango>
if you want to optimize an application, use a profiler
<gunark>
of course
<gunark>
i'm not at the optimization point yet, just doing the prototype, but trying to avoid creating big bottlenecks... without going too far out of my way
<pango>
it's not like processors are afraid of shifting values by 8 bits
<pango>
those things are almost for free
<gunark>
that's true... but why do the shifting, when the shifting is not necessary
<pango>
the wonders of abstraction
alexaandru has left #ocaml []
MisterC has quit [Excess Flood]
cmeme has quit [Excess Flood]
MisterC has joined #ocaml
cmeme has joined #ocaml
delamarche has joined #ocaml
jajs has quit [Remote closed the connection]
smimou has joined #ocaml
bluestorm has joined #ocaml
Leonidas has joined #ocaml
Leonidas has quit [Remote closed the connection]
Leonidas has joined #ocaml
Leonidas has quit [Read error: 104 (Connection reset by peer)]
Leonidas has joined #ocaml
Demitar_ has joined #ocaml
delamarche has quit []
Demitar has quit [Read error: 110 (Connection timed out)]
love-pingoo has quit ["Connection reset by pear"]
stevan has quit ["Leaving"]
malc__ has joined #ocaml
gunark has quit [Read error: 54 (Connection reset by peer)]
<dark_light>
In Event module, I must use synchronize before a event be actually sent? I want send one or more events without blocking. Peharps I should have a hash table with all pending events, and in each loop I do Event.poll in all, and remove it from hashtable when synchronized..
<dark_light>
I was looking for a way to use Event.choose in that situation, but I can't find a way to know which event was selected
<malc__>
01:44 < malc_> dark_light: events will do, if you are okay with blocking behavio
<malc__>
ur
<dark_light>
in that situation i am not ok with blocking
<malc__>
i'm convinced that i'm a casandras reincarnation
<dark_light>
but Event.poll don't blocks anyway
<dark_light>
it seems a great overhead :o
<malc__>
read event.ml (it's tiny), or CML description, or just bite the bullet and use condvars
<dark_light>
there are no event.ml in my installation, o.o
<pango>
event.mli then
<malc__>
no i mean event._ml_
<malc__>
it's part of the source distribution
<dark_light>
hmm
<malc__>
otherlibs/threads/event.ml
<malc__>
274 lines (3.09.0)
delamarche has joined #ocaml
delamarche has quit []
fik has joined #ocaml
shawn has joined #ocaml
Leonidas has quit ["An ideal world is left as an exercise to the reader"]
bluestorm has quit ["Konversation terminated!"]
Demitar has joined #ocaml
smimou has quit ["bli"]
Demitar_ has quit [Read error: 104 (Connection reset by peer)]
Demitar has quit [Read error: 60 (Operation timed out)]
malc__ has quit ["leaving"]
_fab has quit [Read error: 60 (Operation timed out)]