<eni>
method sum : 'a. (<get : number; get_real : float; ..> as 'a) -> _ = fun o -> what does the _ represent in this line?
<eni>
the return of sum?
<flux>
yes
<flux>
I left it blank as it's inferred, but you could of course put the type into it
<adrien>
The Return Of Sum - Starring Xavier Leroy and Jacques Garrigues
<eni>
:p
<adrien>
(sorry :p)
<eni>
should i do explicitly define anything to use self in my code?
<flux>
eni, you mean self the object?
<eni>
yes
<eni>
(this in java0
<flux>
object (this) .. - this now referes to the this-object as in Java
<flux>
btw, this is nice because you can have object literals and you still get to refer to any unshadowed 'this'
<flux>
(ie. an embedded object might use this2)
<eni>
cool
Tobu has quit [Ping timeout: 260 seconds]
<flux>
also, be aware that many (including myself) consider object oriented OCaml to be an advanced subject. it might not be the first way people consider of when trying to accomplish a goal, but rather that's used if the problem calls for it.
<flux>
of course that's not a reason to avoid it, you should study it as it's great :)
<eni>
i just did this to see how objects really work, it was my first time writing a class in ocaml
<eni>
usually i go for java/cpp/python to write oo code
<flux>
things that usually require a class and inheritance in other language can sometimes be expressed as a class type and an object literal. object factories can often be simply be functions returned from other functions. some food for thought ;)
<mrvn>
inheritance can be done with first class modules now.
ankit9 has quit [Read error: Connection reset by peer]
ankit9 has joined #ocaml
jamii has joined #ocaml
<flux>
really? have an example of that? because when I was trying to find one, I noticed in the end they still made use of objects inside..
<flux>
(or records of functions)
<mrvn>
flux: The module is a record of functions internally.
<flux>
does that mean we shouldn't use modules because records will do? or that we shouldn't use objects because modules will do?
<flux>
(modules have the benefit of containing types and constructors, though)
<mrvn>
The advantage of a module over an explicit record is that you can include a module in another and add more functions and still pass it to something expecting the base module.
<mrvn>
And the advantage of objects is that you don't have to pass the module and self explicitly.
<mrvn>
In mostcases it is just a matter of taste.
avsm has joined #ocaml
avsm has quit [Client Quit]
<eni>
modules have the benefit of containing constructors?
<yezariaely>
ist there an easy way to map a string character by character?
<mrvn>
eni: constructors as in multiple.
<yezariaely>
e.g. s.th. like String.map?
<mrvn>
let map s f = let len = String.length s in let t = String.create len in for i = 0 to len - 1 do t.[i] <- f s.[i]; done; t
ankit9 has quit [Ping timeout: 276 seconds]
<yezariaely>
mrvn: thanks, sure I could write that, however the output should not be a string. At the moment I use a reference combined with String.iter to get the characters out.
<yezariaely>
was wondering if there is a more elegant way.
<yezariaely>
anyway thx
<mrvn>
yezariaely: what do you mean? map functions usualy return the same general type as the input.
<mrvn>
do you mean String.fold?
<yezariaely>
mrvn: I know, however here, I have to take a string and return a list of constructor types
<yezariaely>
(the characters only surrounded by a constructor)
<yezariaely>
i.e. I have to represent a string as a list of characters
<yezariaely>
but thanks for your example, I learnt about the "<-" operator. I did not see this one before ;-)
<mrvn>
# let explode s = let rec loop acc = function 0 -> s.[0]::acc | i -> loop (s.[i]::acc) (i-1) in loop [] (String.length s - 1);;
<mrvn>
val explode : string -> char list = <fun>
<mrvn>
List.map f (explode s)
<Ptival>
yezariaely: it's just String.set
<yezariaely>
Ptival: how would String.set be helpful if I have a string and want it to convert it to a list of MyChars ?
<Ptival>
just use explode
<yezariaely>
thx to all of you
<mrvn>
It sucks that ocamls stdlib doesn't have String.to_list and String.of_list
<RichN>
Error: Error while building custom runtime system
<RichN>
Maybe I'll try the mailing list...
RichN has quit [Quit: Gotta go!]
<adrien>
no idea; try without -custom
<eni>
is a match expensive?
fabjan_ is now known as fabjan
ankit9 has quit [Ping timeout: 276 seconds]
<adrien>
no
<adrien>
can you somehow read ASM? (no need to be proficient)
<eni>
ASM?
<adrien>
assembly
<Ptival>
assembly
<eni>
i never compile ocaml code in fact.
<eni>
i just use the toplevel.
<eni>
s/never/almost never/
<adrien>
the efficiency will be slightly different but it'll give you an idea anyway
<adrien>
if you call ocamlopt with -S, it'll keep a .s file with the assembly code the .ml file
<eni>
i was just curious because i found 2 soulutions to a problem, and one of them has pattern matching and the other doesn't.. so i was curious to predict which one would be faster before implementing both of them.
<adrien>
and reading it (even quickly) will show how some things are done
<adrien>
make a file with "match Some 42 with | None -> () | Some _ -> ()", ocamlopt -S -c thatfile.ml
<adrien>
it's also interesting to see with: "let Some x = Some 42"
<adrien>
(the pattern-matching is non-exhaustive; that has an influence on the code)
lorilan has joined #ocaml
<Ptival>
eni: how does the other deal with what the pattern-match does?
<eni>
mod 2
<adrien>
and what does the pattern-matching one does?
<eni>
one (pattern matchin) passes the parity as arguments and uses the fact that even+even = even, even+odd|odd+even = odd, odd+odd=even, and the other does a mod 2 for every num, etc.
<eni>
it seems obvious though that passing an argument to a function is less expensive than doing a mod 2
<Ptival>
you could use two auxiliary functions that assume the parity for even faster :)
<eni>
(the number of fun calls is the same)
Kakadu has joined #ocaml
<eni>
Ptival, you mean two mutual recursive functions?
<Ptival>
yes
<eni>
so having 3, False ; 5, False ; to calculate if 8 (3+5) is even, it would be faster to call (even(8)) than to do match ... False, False -> (3+5), true ?
<Ptival>
or maybe you'd lose speed for lack of tailcallness :\
<Ptival>
dunno
<eni>
i'll just measure the execution times for big big numbers
<eni>
and will loop lots of times to see if the difference exists or no.
<adrien>
and I guess that land (logical and) would be fasterer
<Ptival>
fasterer++zomg!!1!1!
<eni>
:)
<Ptival>
that's as fast as you can get
<adrien>
that was because of the lag: I wasn't sure I had typed the "er"; but I had
<adrien>
:-)
<Ptival>
(then you need quantum computers)
<eni>
i once used a benchmark library don't remember what..
<Ptival>
(and the HH was meant to be sent to your other nazi-adorating channel? :d)
<Ptival>
damn you lag!
<adrien>
'H' is for the control character saying "delete the char"
avsm has quit [Quit: Leaving.]
<adrien>
land should be roughly twice faster as mod
<adrien>
(hmmm, makes me wonder if == wouldn't be faster actually)
<adrien>
eni: it's the generic comparison function; it's _generic_
<thelema>
adrien: == is faster
<adrien>
the question is why does ocaml need to use the generic one; maybe because comparison wouldn't be the "best" way to do it anyway and it's not deemed to be a worthy optimization in the compiler
<adrien>
(why make X faster when Y is much much much faster anyway and does the same)
<eni>
still not as fast as f2
<adrien>
thelema: thanks :-)
<mrvn>
adrien: = should be fast
<thelema>
adrien: ocaml has an optimized = for ints, maybe it doesn't use the same one for bools
<thelema>
(even though it should)
<adrien>
I don't think it'll be easy to beat f2; as far as I'm concerned, I consider this to be the simplest and most-straightforward way to do the function
<mrvn>
= for ints is inlined
<eni>
thelema, can you add a f2bis where or is replaced by || and & by && ?
<thelema>
eni: yes, already written
<adrien>
I think it's really going to be hard to find something faster; even in C/assembly
<eni>
thelema, ah, i didn't see it in the last link..
<thelema>
eni: not uploaded yet; about to run the benchmark
<mrvn>
adrien: a simple xor would be better
<eni>
that should be the fastest according to what you guys were saying
<thelema>
I'm trying to figure out where the logic went in the f2 solution... The assembly has subq, but no and/or
<mrvn>
let f5 (o1:bool) o2 = not (o1 != o2)
<thelema>
gist updated with f5 = f2 with && and ||; same result as f2
<thelema>
mrvn: that will be f6
<mrvn>
It's strange that != is inlined but = is not
<thelema>
!= is opposite of ==
<djcoin>
mrvn: != is the contrary of ==
<djcoin>
yep
<djcoin>
<> if opposite of =
<mrvn>
ahh, I forgot. <> then.
<pippijn>
mrvn: != is physical identity
<mrvn>
damn, <> is a callq too.
<pippijn>
maybe <> is also inlined if both arguments are known to be int
<pippijn>
or bool
<djcoin>
Can you specify which fun you want to inline ?
<djcoin>
(I saw that on f#)
<mrvn>
djcoin: this isn't inline. it depends on wether the compiler has MM code for it or not.
<thelema>
djcoin: no, ocaml's inliner doesn't let the user pick
<djcoin>
ok
<eni>
thelema, the benchmark is in fact running these in the toplevel right?
<mrvn>
It looks to me like = and <> lack the MM code sniplets for bools. With int it doesn't use callq.
<thelema>
eni: no, as native compiled code
<eni>
ok.
<thelema>
mrvn: that's what I'm benchmarking now.
<adrien>
mrvn: agreed: xor would probably be faster but not _that_ much and then you wouldn't get any faster
<mrvn>
adrien: one opcodes instead of 4
<thelema>
mrvn: opcodes don't matter too much, micro-opts matter
<thelema>
s/opts/ops/
<mrvn>
Is there a way to specify ((o1 & o2) or ((not o1) & (not o2))) without lazy evaluation?
<thelema>
land, lor
<thelema>
but that's for ints
<mrvn>
thelema: so Obj.magic them to int?
<thelema>
sure.
<thelema>
my final version is uploaded to the same gist. apparently not even int = is faster than what ocamlopt comes up with for the long boolean expression
<djcoin>
Do you know some documentation, papers or tutorials to dive into ocaml internals ? (compilation, Obj.Magic etc. ?)
<mrvn>
It really is too bad there isn't a syntax to write embedded MM code in ocaml.
<thelema>
djcoin: rwmjones wrote some nice blog posts about ocaml internals
<mrvn>
Why can't ocaml work with untagged integers as intermediate results?
<thelema>
gc might run?
<djcoin>
Indeed ! I saw its post a few weeks ago. I have to read them for good
<mrvn>
thelema: not in 1 - (i1 lxor i2)
<thelema>
extra bookkeeping to make sure everything is acceptable before gc
<mrvn>
It tags (i1 lxor i2), then it subs 0x3 and tags that again.
mika1 has quit [Remote host closed the connection]
mika1 has joined #ocaml
<mrvn>
Would be better to sub 0x2
Kakadu has quit [Quit: Page closed]
<thelema>
threading?
<mrvn>
thelema: since when is ocamls threading preemptive?
<hcarty>
mrvn: Since when is it not?
<mrvn>
hcarty: since ever. you need to release the runtime lock for other threads to run.
<hcarty>
mrvn: Doesn't OCaml manage that unless you're calling out to C?
<mrvn>
hcarty: iirc the GC does it when it gets called.
<mrvn>
But you don't get thread switches in the middle of an expression that doesn't call the GC.
<thelema>
in bytecode, yes. in native code, iirc, ocaml has two threading models, and system threads are preemptive
<thelema>
oops, bytecode has the two threading models, native has only system threads
<mrvn>
thelema: the system threads are, but all but one is blocked aquireing the runtime lock.
<thelema>
ah.. .hmmm
snearch has quit [Quit: Verlassend]
<mrvn>
To test try to write some ocaml code that runs a long time without invoking the GC.
<thelema>
yes, I've heard of that problem, requiring a call to Thread.yield()
<mrvn>
It it where truely preemptive the thread switch could happen between an integer opreation that destroys the tag and the operation restoring the tag. And then the GC could thing the register holds a pointer.
<thelema>
yes, that's what I've been trying to work out, I guess all the extra safety isn't needed
<thelema>
but I guess that the optimizer only works at the level before tags are introduced
<thelema>
and the last codegen phase is pretty dumb about re-tagging
<mrvn>
Its odd, tagging should be like boxing and the compiler knows how to unbox some stuff.
<thelema>
I'd guess that boxing is taken care of at a different level than tagging
lorilan has quit [Quit: Quitte]
<mrvn>
1 - (i1 lxor i2) also shows that ocaml doesn't do register allocation properly. There is a needless move from one register to the other in there.
<thelema>
I thought ocaml did graph coloring for register allocation... unless you're using that linear scan branch that came out...
<thelema>
I guess that even the graph coloring algorithm takes some shortcuts
<mrvn>
thelema: why doesn't it "xor %rax,%rbx" and use %rbx instead of $rdi for the rest?
<thelema>
mrvn: I see. I don't know.
<mrvn>
1 - (i2 lxor i1) does.
<mrvn>
Does it lack the knowledge that xor a,b == xor b,a?
<thelema>
just knowing that doesn't enable it to apply that rule everywhere to see if that would improve the output.
<mrvn>
true, it has to combine that with register allocation
landonf has left #ocaml []
cago has quit [Quit: Leaving.]
mika1 has quit [Remote host closed the connection]
<mrvn>
I also wonder how much one would gain from optimizing the asm output. Ocaml doesn't seem to interleave operations.
<mrvn>
e.g. mov $0x3,%rax could be before or $0x1,%rdi
<mrvn>
or does modern cpu pipelining reorder that internally enough that it doesn't matter?
<pippijn>
mrvn: I think it will
<mrvn>
What I always find most interesting is that despide everything ocaml DOESN't do it generaly runs no worse than twice as long as c.
<mrvn>
and often nearly the same.
<pippijn>
reducing polymorphism helps a lot, too
<pippijn>
in this case, you already did that
<mrvn>
pippijn: you mean let f x y = x = y vs. let f (x:int) y = x = y?
<pippijn>
yes
<pippijn>
or involving <
lorilan has joined #ocaml
<mrvn>
I'm not sure that actualy helps so much in real live. Such simple functions do get inlined and then it usualy knows the type. Doesn't the inlined version then automatically loose the polymorphism?
<pippijn>
I don't think so
<mrvn>
let f1 x y = x = y let f2 (x:int) y = x = y let f3 (x:int) y = f1 x y
<mrvn>
f1 uses callq as it must, f2 uses inlined = and f3 callq again. :(
emmanuelux has quit [Remote host closed the connection]
<mrvn>
pippijn: that seems rather stupid. Lossing the polymorphism is a huge speed up and the optimizer/inliner should figure that out.
<pippijn>
yeah
<mrvn>
I mistakenly thought the inliner would be higher up and the polymorphism thingy would be during code generation.
<mrvn>
Seems like the type information isn't updated when inlining or something.
<hcarty>
mrvn: Thanks for the GC clarifications.
<thelema>
OCaml's inliner is certainly a weak point of its implementation, and could definitely be improved
<hcarty>
mrvn: Regarding inlining and polymorphism I think there is a bug report or few about that
<hcarty>
With some activity recently if I recall correctly
<thelema>
hcarty: the ocamlpro folks were working on inlining; I'm not sure how far they were able to get
<thelema>
I just want inlining of functions passed as parameters.
<mrvn>
thelema: That kind of is reverse inlining. :)
maufred has quit [Ping timeout: 260 seconds]
maufred has joined #ocaml
<mrvn>
thelema: does inlining work with functors (e.g. does it inline the compare function in a Set)?
rby_ has quit [Quit: leaving]
lorilan has quit [Remote host closed the connection]
yezariaely has quit [Quit: leaving]
lorilan has joined #ocaml
ftrvxmtrx has quit [Quit: Leaving]
larhat has quit [Quit: Leaving.]
err404 has joined #ocaml
rwmjones has quit [Ping timeout: 265 seconds]
<mfp>
mrvn: no, calls to functions in the module parameter always go through the internal record-like structure
smerz has joined #ocaml
emmanuelux has joined #ocaml
rwmjones has joined #ocaml
letrec has joined #ocaml
andreypopp has joined #ocaml
avsm has quit [Quit: Leaving.]
<eni>
when using = is there a memory read?
datkin has quit [Ping timeout: 244 seconds]
<thelema>
eni: ?? depends on whether the values being (=)'ed are in registers or not. Most likely, yes, there is a memory read
<eni>
thelema, that's why the or /not version was faster i think.
<thelema>
umm, it would need to do the same amount of memory read as (=)
<thelema>
mrvn: exactly - I want to give my code in a reverse-inlined manner and have the compiler inline it for performance.
<Ptival>
scandal: Bob Harper wrote O'Caml!!!
<thelema>
mrvn: as to functors, it can't inline the compare function in Set, as this functor isn't applied until runtime.
<thelema>
Ptival: Bob Harper wrote some OCaml code which he compiled with the INRIA OCaml compiler? or he wrote some code that's part of the OCaml compiler?
<Ptival>
thelema: haha, I actually meant that he wrote "O'Caml" instead of "OCaml" in his presentation at Milner Symposium :D
<thelema>
oh. Maybe he was referring to the irish cousin of OCaml.
<thelema>
or maybe the proper spelling of OCaml has been unclearly communicated.
avsm has joined #ocaml
jonafan_ is now known as jonafan
rossberg has quit [Ping timeout: 272 seconds]
rossberg has joined #ocaml
eni has quit [Quit: Leaving]
djcoin has quit [Quit: WeeChat 0.3.2]
letrec has quit [Ping timeout: 272 seconds]
jamii has quit [Read error: No route to host]
avsm has quit [Quit: Leaving.]
<hcarty>
thelema: That's why the name was changed - Ireland kept getting all the credit :-)
Zedrikov has joined #ocaml
Zedrikov is now known as NamelessOne
Zedrikov has joined #ocaml
Zedrikov has quit [Read error: Connection reset by peer]
Zedrikov has joined #ocaml
pangoafk is now known as pango
yroeht has quit [Ping timeout: 265 seconds]
yroeht has joined #ocaml
jamii has joined #ocaml
jamii has quit [Ping timeout: 245 seconds]
<Drakken>
Ptival sorry about that dumb question this morning. What I really needed to ask about is ocamlbuild.
<thelema>
I just caught the end of the Milner Symposium webcast; is anyone recording it?
<Drakken>
Compound prepreprocessing commands work with ocamlc, but I'm having trouble using them with ocamlbuild.
<Drakken>
i.e. [ocamlc -pp "camlp4 foo.cmo" bar.ml] works, but [ocamlbuild bar.byte] fails with [<bar.ml>: pp("camlp4 foo.cmo")] in _tags.
<thelema>
Drakken: what command does ocamlbuild produce?
<Drakken>
Thank you.
<Drakken>
Apparently the quotation marks are redundant.
jamii has joined #ocaml
<Drakken>
And ocamlbuild cds into _build, so foo.cmo needs a "../" in front of it.
<thelema>
Drakken: if possible, you should copy/build foo.cmo in _build
<Drakken>
without the quotation marks :)
<thelema>
:)
<Drakken>
thelema actually, the file is ../foo/foo.ml. It's a utility.
<Drakken>
So from _build it's ../../foo/foo.ml :)
<thelema>
and why isn't it built by ocamlbuild?
<thelema>
oh, it's outside your source tree
<Drakken>
right
<thelema>
so why isn't it installed somewhere?
<Drakken>
I guess it should be.
<Drakken>
I just haven't gotten around to it.
<Drakken>
I mean foo.cmo, not foo.ml
Anarchos has joined #ocaml
ftrvxmtrx has joined #ocaml
sivoais has quit [Quit: leaving]
sivoais has joined #ocaml
sivoais has quit [Quit: Lost terminal]
avsm has joined #ocaml
sivoais has joined #ocaml
sivoais has quit [Client Quit]
sivoais has joined #ocaml
_andre has quit [Quit: leaving]
larhat has joined #ocaml
Tobu has quit [Ping timeout: 272 seconds]
<flux>
is there a nicer way to go through two floating pointer values than: (1.0, 10.0) --. y_dim |> BatEnum.iter **> fun y -> (1.0, 10.0) --. x_dim |> BatEnum.iter **> fun x -> ..
<pippijn>
go through?
<flux>
as in operate on points (1.0, 1.0); (11.0, 1.0); (21.0, 1.0) .. (1.0, 11.0); (11.0, 11.0); ..
landonf has joined #ocaml
landonf has left #ocaml []
Tobu has joined #ocaml
<pippijn>
I don't know these operators
<pippijn>
and I don't really like using lots of custom operators
<adrien>
:-)
andreypopp has quit [Quit: Computer has gone to sleep.]
snearch has joined #ocaml
oriba has joined #ocaml
err404 has quit [Remote host closed the connection]
wtetzner has joined #ocaml
tufisi has quit [Ping timeout: 276 seconds]
wtetzner has quit [Remote host closed the connection]
wtetzner has joined #ocaml
Zedrikov has quit [Quit: Bye all, see you next time!]
NamelessOne has quit [Quit: Bye all, see you next time!]
Anarchos has quit [Quit: Vision[0.9.7-H-090423]: i've been blurred!]
jamii has quit [Ping timeout: 252 seconds]
jamii has joined #ocaml
jamii has quit [Read error: Connection reset by peer]
Xizor has quit [Ping timeout: 260 seconds]
snearch has quit [Quit: Verlassend]
zorun has quit [Read error: Connection reset by peer]