S11001001 has quit [Quit: ERC Version 5.3 (IRC client for Emacs)]
ygrek has joined #ocaml
struktured has joined #ocaml
dant3 has joined #ocaml
struktured has quit [Ping timeout: 272 seconds]
dant3 has quit [Ping timeout: 248 seconds]
ollehar has joined #ocaml
struktured has joined #ocaml
jpdeplaix has quit [Ping timeout: 250 seconds]
ollehar has quit [Ping timeout: 246 seconds]
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
zpe has quit [Read error: Connection reset by peer]
ontologiae has quit [Ping timeout: 245 seconds]
jpdeplaix has joined #ocaml
dant3 has joined #ocaml
appleby has joined #ocaml
<appleby>
can soemone explain to me this code
<appleby>
let display_map = fun (geomap:G.widget) xml_map
<appleby>
specifically the geomap:G.widget part?
<Drup>
it's a type anotation
<Drup>
geomap is the name of the argument, G.widget is the type
dant3 has quit [Ping timeout: 241 seconds]
<appleby>
oh okay
<appleby>
class or object?
r0b2 has joined #ocaml
<Drup>
well, it's a type
<Drup>
so it can't be an object
struktured has quit [Ping timeout: 260 seconds]
r0b1 has quit [Ping timeout: 260 seconds]
mrvn has quit [Ping timeout: 260 seconds]
mrvn has joined #ocaml
watermind has quit [Quit: Konversation terminated!]
csakatoku has joined #ocaml
kyrylo has quit [Ping timeout: 250 seconds]
struktured has joined #ocaml
venk has joined #ocaml
lopex has quit [Ping timeout: 276 seconds]
lopex has joined #ocaml
zpe has joined #ocaml
dant3 has joined #ocaml
dant3 has quit [Ping timeout: 260 seconds]
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
zpe has quit [Ping timeout: 260 seconds]
csakatoku has quit [Remote host closed the connection]
cdidd has quit [Read error: Connection reset by peer]
<bicgena>
ive never used functional programming languages before (only some messing around with HTML and CSS when i was like 13 and some FORTRAN for science research) and im getting used to it. all our problem sets are in OCaml and its like meditating on zen koans. i look at a problem for a looooong time, then type the answer.
<Drup>
:D
<Drup>
there is a paper called "the zen of functional programming" or something like that.
<appleby>
Drup
<appleby>
can you explain to me this code
<appleby>
let create_geomap = fun switch_fullscreen editor_frame ->
<appleby>
let geomap = new G.widget ~srtm:!srtm ~height:500 ~projection:!projection () in
<appleby>
so create_geomap is a function? which returns the value of fun switch_fullscreen editor_frame?
<appleby>
where switch_fullscreen is the name of another function?
<Drup>
appleby: you should factor the argument in the function declaration, it's nicer
<appleby>
this is a library
<Drup>
not important, but nicer
<appleby>
not my code
<Drup>
which library ?
<appleby>
Paparazzi UAV
<bicgena>
Drup: did you feel the same way as I about Ocaml? :)
<appleby>
so everything that is evaluated after the -> would be the return of the function?
<Drup>
appleby: yes
<Drup>
appleby: but keep in mind it can return a function too
<appleby>
k
yacks has joined #ocaml
<Drup>
bicgena: well, I almost started programming by ocaml, so it's a little bit different for me
<Drup>
bicgena: but I do have this feeling of enlightenment when trying to write stuff in a dependently typed language like Agda.
<Drup>
(usually, without a lot of success :D)
hnrgrgr has quit [Ping timeout: 264 seconds]
<bicgena>
Drup: wow,... almost started programming by ocaml? you don't hear that often
<bicgena>
then again, it seems like some university courses are using ocaml as a first language
<bicgena>
especially French ones
<Drup>
bicgena: it's pretty common for a certain category of french student =)
<bicgena>
why do you think that is?
<Drup>
because it's in the official program
<Drup>
:D
<Drup>
"where the student happily applied the remainder of his appetite." <3
<Drup>
bicgena: thanks for the link, it's hilarious x)
csakatoku has joined #ocaml
dant3 has joined #ocaml
dant3 has quit [Ping timeout: 248 seconds]
sorethroat has joined #ocaml
<covi>
In what places do I need to use 'in' after 'let x = ..' and in what places do I not need to (e.g. inside a 'struct..end')
<Drup>
everytime it's a top level declaration, you don't add the in
<Drup>
because there is nothing to be in :)
<Drup>
(inside a struct, it's conceptually still the top level of a module, even if this module is inside another one)
keithflower has joined #ocaml
ygrek has quit [Ping timeout: 265 seconds]
zpe has joined #ocaml
sorethroat has quit [Ping timeout: 246 seconds]
<bicgena>
Drup: once i tough of using a while loop in a problem and i felt really ashamed afterwards. also when i finish a problem and its 10 lines of code, but i know it can be written more elegantly in less lines of code, i get frustrated.
<bicgena>
though*
<Drup>
I don't have any issue with while loop, except they are not powerful enough for what I want most of the time.
<bicgena>
why not?
<bicgena>
you just use recursion?
<Drup>
most of the time, when people write a while loop, what they really want is a fold over something, but they juste write it with while + references
<Drup>
and fold is just nicer for this stuff
<Drup>
or just recursion, of course
<Drup>
it's not always the case, there are counter examples, as with everything :)
zpe has quit [Ping timeout: 260 seconds]
<bicgena>
Drup: there are?
<bicgena>
can you think of one?
<Drup>
unsurprisingly, every complicated arrays walking
ggole has joined #ocaml
<bicgena>
Drup: what does that mean?
<Drup>
when you want to access elements of an array in a weird order to do weird stuff
tlockney has quit [Quit: I may return, one day...]
smondet has quit [Remote host closed the connection]
smondet has joined #ocaml
<Drup>
(usually, math or image processing :p)
tlockney has joined #ocaml
zpe has joined #ocaml
<bicgena>
Drup: true, but so far our homework is elementary enough such that the purpose is for us to learn how to use recursion effectively and think in recursion. the problem in question was to write a function "few_divisors n m" where if n has fewer than m divisors, the function returns true. the meat of the problem was finding a way to find the number of divisors
<bicgena>
of n, so pretty much all of us did it a brute-force way: starting from 1 (or from n, depending on if youre counting up backwards or upwards), if n mod (that number = 0), then count that number as a divisor.
<bicgena>
Drup: at first i was like "wha how do i write an algorithm to find the prime factorization i didnt think the class would be that advanced" but then i realized this was the most accessible way to do it
tlockney has quit [Quit: I may return, one day...]
tlockney has joined #ocaml
tlockney has left #ocaml []
<Drup>
you can do the prime factorization quite easily, if not very optimized =)
<bicgena>
Drup: how?
<Drup>
star the scaning for divider from 2, if you find a divider k, store k and look for the divider of (n/k) again
<Drup>
hum, I should have gave hint instead of telling you ::
ygrek has joined #ocaml
<bicgena>
Drup: okay, I ignored what you said, could you give me a hint instead?
<Drup>
:D
<Drup>
bicgena: first, imagine you have a method to find a prime divider of a number, how would you compute the prime decomposition ?
philtor has quit [Ping timeout: 250 seconds]
<bicgena>
Drup: I don't know
tlockney_away has joined #ocaml
tlockney_away is now known as tlockney
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
tlockney has quit [Quit: I may return, one day...]
zpe has quit [Ping timeout: 250 seconds]
tlockney_away has joined #ocaml
tlockney_away is now known as tlockney
zpe has joined #ocaml
sorethroat has joined #ocaml
jao has quit [Ping timeout: 245 seconds]
tlockney is now known as tlockney_away
tlockney_away is now known as tlockney
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
appleby has quit [Quit: appleby]
zpe has quit [Ping timeout: 252 seconds]
axiles has joined #ocaml
mcclurmc has quit [Remote host closed the connection]
lostcuaz has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dant3 has joined #ocaml
dant3 has quit [Remote host closed the connection]
dant3 has joined #ocaml
sorethroat has quit [Ping timeout: 260 seconds]
csakatoku has quit [Remote host closed the connection]
sorethroat has joined #ocaml
dant3 has quit [Remote host closed the connection]
dch has left #ocaml []
dant3 has joined #ocaml
sorethroat has quit [Ping timeout: 245 seconds]
csakatoku has joined #ocaml
dant3 has quit [Ping timeout: 245 seconds]
dant3 has joined #ocaml
thizanne has quit [Ping timeout: 260 seconds]
Guest_ has joined #ocaml
thizanne has joined #ocaml
thizanne has quit [Ping timeout: 260 seconds]
thizanne has joined #ocaml
thizanne has quit [Ping timeout: 265 seconds]
covi has quit [Remote host closed the connection]
zpe has joined #ocaml
Kakadu has joined #ocaml
zpe has quit [Ping timeout: 265 seconds]
dant3 has quit [Remote host closed the connection]
watermind has quit [Quit: Konversation terminated!]
watermind has joined #ocaml
cdidd has quit [Remote host closed the connection]
<gasche>
ggole: tail-recursion modulo constructors can be expressed in Mezzo using destination-passing style
<gasche>
(this is also what we (unsafely) use in Batteries to write tail-recursive List.map without reversing lists)
<ggole>
gasche: I'm pretty sure you can get rid of the write barrier, too
<ggole>
Or almost get rid of it: by moving it just before the call to the gc
<ggole>
(From what I can tell, code is so cold there it might as well not exist.)
<gasche>
I don't know about that, but it's true that destination-passing style has a very simple region typing
<ggole>
How does Batteries do it? Just Obj.magic?
<ggole>
eg, with a mutable record type.
fds has joined #ocaml
<flux>
yes
<ggole>
Right.
<ggole>
Shame to have to hack up the source like that.
<gasche>
a pet projet thunk of mine is to implement those functions in Mezzo, and compile that back to OCaml
<gasche>
unfortunately Mezzo's prototype is not yet ready to "extract" libraries (as opposed to complete progras), or provide an OCaml FFI
<avsm>
gasche: would work through a ctypes ffi :-)
watermind has quit [Quit: Konversation terminated!]
watermind has joined #ocaml
watermind has quit [Read error: Connection reset by peer]
watermind has joined #ocaml
ygrek has joined #ocaml
shinnya has joined #ocaml
saml has joined #ocaml
appleby has quit [Quit: appleby]
Guest____ has quit [Quit: Computer has gone to sleep.]
<bernardofpc>
gasche: would that be easier (to write/maintain) than to write the corresponding C function for List.map ?
mchqwerty has joined #ocaml
<adrien_oww>
well, for List.map, doing it in C is going to be quick and simple
<adrien_oww>
but then you'll have to do everything again for other functions
<ggole>
Hmm, OCaml emits some very strange code for functions with many arguments.
<adrien_oww>
how so?
<ggole>
Redundant instructions, puts the arguments in two locations, etc
<adrien_oww>
are you sure it's not the call convention?
<ggole>
I'm not sure what the deal is with the two locations (it's some on the stack, some in vector called caml_extra_params)
<ggole>
The extra instructions are pretty obvious (although not that big a deal)
<ggole>
They look like movl $k, %eax/movl %eax, 8(%esp)
<ggole>
There's no point enregistering the constant.
<adrien_oww>
C stub?
<ggole>
Then after that, they're copied from the stack into caml_extra_params.
<ggole>
Well, it's caml_applyK
ollehar has quit [Ping timeout: 246 seconds]
mcclurmc has joined #ocaml
appleby has joined #ocaml
hnrgrgr has joined #ocaml
ollehar has joined #ocaml
WraithM has quit [Quit: Lost terminal]
skchrko has quit [Ping timeout: 260 seconds]
Thooms has joined #ocaml
skchrko has joined #ocaml
avsm has quit [Quit: Leaving.]
dant3 has quit [Remote host closed the connection]
ocp has joined #ocaml
ygrek has quit [Ping timeout: 250 seconds]
lostcuaz has joined #ocaml
appleby has quit [Quit: appleby]
jonludlam has joined #ocaml
dsheets has quit [Ping timeout: 245 seconds]
tane has joined #ocaml
cago has left #ocaml []
<gasche>
bernardofpc: I like writing typed code better than writing fast code; having a use of Mezzo for performance reason would be fun, while I have no particular interest in writing C
<gasche>
of course if people know how to write correct C functions and want to contribute, pull requests are welcome
agnoctone has quit [Quit: Page closed]
<companion_cube>
o/ gasche
<adrien_oww>
actually for List.map there might be a big issue: you need an ocaml function so you're essentially calling OCaml from C and that's not very fast
mchqwerty has quit [Ping timeout: 272 seconds]
<ggole>
You could write it in assembly.
<ggole>
(This is not the best idea.)
zpe has joined #ocaml
cdidd has joined #ocaml
avsm has joined #ocaml
Yoric has quit [Ping timeout: 265 seconds]
Thooms has quit [Ping timeout: 272 seconds]
Yoric has joined #ocaml
ygrek has joined #ocaml
mye has joined #ocaml
Thooms has joined #ocaml
japesinator has quit [Ping timeout: 252 seconds]
japesinator has joined #ocaml
Yoric has quit [Ping timeout: 265 seconds]
dant3 has joined #ocaml
dant3 has quit [Read error: Connection reset by peer]
dant3 has joined #ocaml
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
Thooms has quit [Quit: WeeChat 0.3.8]
zpe has quit [Ping timeout: 245 seconds]
mcclurmc has quit [Remote host closed the connection]
dsheets has joined #ocaml
Kakadu has quit [Ping timeout: 245 seconds]
dant3 has quit [Ping timeout: 250 seconds]
appleby has joined #ocaml
appleby_ has joined #ocaml
appleby has quit [Ping timeout: 265 seconds]
appleby_ is now known as appleby
skchrko has quit [Quit: Leaving]
mcclurmc has joined #ocaml
mcclurmc has quit [Remote host closed the connection]
mcclurmc has joined #ocaml
keithflower has joined #ocaml
S11001001 has joined #ocaml
S11001001 has quit [Changing host]
S11001001 has joined #ocaml
appleby has quit [Quit: appleby]
Yoric has joined #ocaml
zpe has joined #ocaml
jwatzman|work has joined #ocaml
jwatzman|work has quit [Changing host]
jwatzman|work has joined #ocaml
lostcuaz has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
avsm has quit [Quit: Leaving.]
avsm has joined #ocaml
<bernardofpc>
adrien_oww: oh, I didn't know that C calling OCaml would be slow
Anarchos has joined #ocaml
<bernardofpc>
(the other way around is "fast", or is it just "equally slow" ?)
<bernardofpc>
(in that you have to put some glue for the calling conventions etc)
Kakadu has joined #ocaml
avsm has quit [Ping timeout: 264 seconds]
ggherdov has quit [Ping timeout: 265 seconds]
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
kyrylo has quit [Ping timeout: 248 seconds]
mmachenry has joined #ocaml
zpe has quit [Ping timeout: 245 seconds]
ggherdov has joined #ocaml
jao has joined #ocaml
jao has quit [Changing host]
jao has joined #ocaml
ollehar has quit [Ping timeout: 246 seconds]
mreca has joined #ocaml
appleby has joined #ocaml
dant3 has joined #ocaml
Yoric has quit [Ping timeout: 265 seconds]
ocp has quit [Ping timeout: 246 seconds]
<adrien>
bernardofpc: calling C from OCaml is fast: a few insns
<adrien>
the other way round is at least 10 times more expensive iirc
<pippijn>
the other way around is a closure call
<adrien>
there's at least a lookup involved (once and then can be cached) but I think that after there is still more work
<adrien>
well :P
<pippijn>
calling C from ocaml is a direct function call
<pippijn>
you could hack the closure call out if you're sure something is not a closure, then it can be an indirect call
dant3 has quit [Ping timeout: 248 seconds]
<pippijn>
or even a direct call if you know the function you're calling at compile time
<companion_cube>
it's using caml_apply?
<companion_cube>
that must look at the arity of the function, and see whether all arguments have been provided or not
<pippijn>
I wonder how it does that
<pippijn>
where is the metadata stored of the function arity?
<ggole>
In the closure structure afaik
<companion_cube>
I'd think it was in the function code itself
<companion_cube>
but the closure does contain the number of arguments it captures
<companion_cube>
(so you need to compute closure_num + arg_num and see whether it's equal to the expected arity)
<companion_cube>
(if it's smaller you create a new closure)
<ggole>
I don't think c functions are called directly, either
<ggole>
They go through caml_c_call
sorethroat has joined #ocaml
mort___ has joined #ocaml
<pippijn>
hm, you're right
<ggole>
Although the arguments are pushed to the stack