kaustuv changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | 3.11.1 out now! Get yours from http://caml.inria.fr/ocaml/release.html
lutter has quit [bartol.freenode.net irc.freenode.net]
Olf has quit [bartol.freenode.net irc.freenode.net]
Hadaka has quit [bartol.freenode.net irc.freenode.net]
Modius has quit [bartol.freenode.net irc.freenode.net]
patronus has quit [bartol.freenode.net irc.freenode.net]
flx_ has quit [bartol.freenode.net irc.freenode.net]
M| has quit [bartol.freenode.net irc.freenode.net]
xevz has quit [bartol.freenode.net irc.freenode.net]
psnively has quit [bartol.freenode.net irc.freenode.net]
__marius__ has quit [bartol.freenode.net irc.freenode.net]
caligula has quit [bartol.freenode.net irc.freenode.net]
qwr_ has quit [bartol.freenode.net irc.freenode.net]
ppsmimou has quit [bartol.freenode.net irc.freenode.net]
peddie_ has quit [bartol.freenode.net irc.freenode.net]
mehdid has quit [bartol.freenode.net irc.freenode.net]
petchema has quit [bartol.freenode.net irc.freenode.net]
tab has quit [bartol.freenode.net irc.freenode.net]
mattam has quit [bartol.freenode.net irc.freenode.net]
rbancroft has quit [bartol.freenode.net irc.freenode.net]
mal`` has quit [bartol.freenode.net irc.freenode.net]
raboof has quit [bartol.freenode.net irc.freenode.net]
gim has quit [bartol.freenode.net irc.freenode.net]
slash_ has quit [bartol.freenode.net irc.freenode.net]
deavid has quit [bartol.freenode.net irc.freenode.net]
seafood has quit [bartol.freenode.net irc.freenode.net]
wysek has quit [bartol.freenode.net irc.freenode.net]
bohanlon has quit [bartol.freenode.net irc.freenode.net]
authentic has quit [bartol.freenode.net irc.freenode.net]
Camarade_Tux has quit [bartol.freenode.net irc.freenode.net]
schme has quit [bartol.freenode.net irc.freenode.net]
anders^^ has quit [bartol.freenode.net irc.freenode.net]
nimred has quit [bartol.freenode.net irc.freenode.net]
munga has quit [bartol.freenode.net irc.freenode.net]
sbok has quit [bartol.freenode.net irc.freenode.net]
hkBst has quit [bartol.freenode.net irc.freenode.net]
kaustuv has quit [bartol.freenode.net irc.freenode.net]
jeddhaberstro has quit [bartol.freenode.net irc.freenode.net]
animist has quit [bartol.freenode.net irc.freenode.net]
bartiosze has quit [bartol.freenode.net irc.freenode.net]
cmeme has quit [bartol.freenode.net irc.freenode.net]
bacam has quit [bartol.freenode.net irc.freenode.net]
holgr has quit [bartol.freenode.net irc.freenode.net]
Amorphous has quit [bartol.freenode.net irc.freenode.net]
svenl has quit [bartol.freenode.net irc.freenode.net]
mellum has quit [bartol.freenode.net irc.freenode.net]
Asmadeus has quit [bartol.freenode.net irc.freenode.net]
easy4 has quit [bartol.freenode.net irc.freenode.net]
aij_ has quit [bartol.freenode.net irc.freenode.net]
rwmjones-afk has quit [bartol.freenode.net irc.freenode.net]
ertai has quit [bartol.freenode.net irc.freenode.net]
TaXules has quit [bartol.freenode.net irc.freenode.net]
mfp_ has quit [bartol.freenode.net irc.freenode.net]
prigaux has quit [bartol.freenode.net irc.freenode.net]
brendan has quit [bartol.freenode.net irc.freenode.net]
Demitar has quit [bartol.freenode.net irc.freenode.net]
tsuyoshi has quit [bartol.freenode.net irc.freenode.net]
tarbo2 has quit [bartol.freenode.net irc.freenode.net]
sgnb` has quit [bartol.freenode.net irc.freenode.net]
mbishop has quit [bartol.freenode.net irc.freenode.net]
smimou has quit [bartol.freenode.net irc.freenode.net]
gildor has quit [bartol.freenode.net irc.freenode.net]
fremo has quit [bartol.freenode.net irc.freenode.net]
tonyIII has quit [bartol.freenode.net irc.freenode.net]
jlouis has quit [bartol.freenode.net irc.freenode.net]
ozzloy has quit [bartol.freenode.net irc.freenode.net]
erickt has quit [bartol.freenode.net irc.freenode.net]
jonafan has quit [bartol.freenode.net irc.freenode.net]
r0bby has quit [bartol.freenode.net irc.freenode.net]
Pepe_ has quit [bartol.freenode.net irc.freenode.net]
maskd has quit [bartol.freenode.net irc.freenode.net]
julm has quit [bartol.freenode.net irc.freenode.net]
bernardofpc has quit [bartol.freenode.net irc.freenode.net]
Ori_B has quit [bartol.freenode.net irc.freenode.net]
poucet has quit [bartol.freenode.net irc.freenode.net]
BiDOrD has quit [bartol.freenode.net irc.freenode.net]
tomaw has quit [bartol.freenode.net irc.freenode.net]
ski__ has quit [Nick collision]
lanaer has quit [Nick collision]
acatout has quit [Nick collision]
acatout has joined #ocaml
lanaer has joined #ocaml
ski__ has joined #ocaml
seafood has joined #ocaml
psnively has joined #ocaml
kaustuv has joined #ocaml
peddie_ has joined #ocaml
jeddhaberstro has joined #ocaml
slash_ has joined #ocaml
julm has joined #ocaml
smimou has joined #ocaml
Demitar has joined #ocaml
lutter has joined #ocaml
deavid has joined #ocaml
tomaw has joined #ocaml
poucet has joined #ocaml
BiDOrD has joined #ocaml
Ori_B has joined #ocaml
bernardofpc has joined #ocaml
maskd has joined #ocaml
sgnb` has joined #ocaml
nimred has joined #ocaml
anders^^ has joined #ocaml
rwmjones-afk has joined #ocaml
authentic has joined #ocaml
hkBst has joined #ocaml
Amorphous has joined #ocaml
mfp_ has joined #ocaml
easy4 has joined #ocaml
r0bby has joined #ocaml
bacam has joined #ocaml
animist has joined #ocaml
tonyIII has joined #ocaml
Pepe_ has joined #ocaml
TaXules has joined #ocaml
schme has joined #ocaml
ozzloy has joined #ocaml
cmeme has joined #ocaml
bohanlon has joined #ocaml
Camarade_Tux has joined #ocaml
wysek has joined #ocaml
jonafan has joined #ocaml
holgr has joined #ocaml
brendan has joined #ocaml
munga has joined #ocaml
erickt has joined #ocaml
svenl has joined #ocaml
tarbo2 has joined #ocaml
sbok has joined #ocaml
mbishop has joined #ocaml
tsuyoshi has joined #ocaml
gildor has joined #ocaml
aij_ has joined #ocaml
bartiosze has joined #ocaml
mellum has joined #ocaml
prigaux has joined #ocaml
Asmadeus has joined #ocaml
ertai has joined #ocaml
fremo has joined #ocaml
jlouis has joined #ocaml
tab has joined #ocaml
raboof has joined #ocaml
gim has joined #ocaml
rbancroft has joined #ocaml
mattam has joined #ocaml
mal`` has joined #ocaml
petchema has joined #ocaml
mehdid has joined #ocaml
qwr_ has joined #ocaml
ppsmimou has joined #ocaml
xevz has joined #ocaml
flx_ has joined #ocaml
M| has joined #ocaml
patronus has joined #ocaml
Olf has joined #ocaml
Modius has joined #ocaml
Hadaka has joined #ocaml
__marius__ has joined #ocaml
caligula has joined #ocaml
maxote has quit [SendQ exceeded]
maxote has joined #ocaml
slash_ has quit [Client Quit]
psnively has quit []
verte has joined #ocaml
Amorphous has quit [Read error: 110 (Connection timed out)]
rhar has joined #ocaml
Amorphous has joined #ocaml
authentic has quit [Remote closed the connection]
BiDOrD has quit [Read error: 60 (Operation timed out)]
authentic has joined #ocaml
BiDOrD has joined #ocaml
hkBst has quit [Read error: 104 (Connection reset by peer)]
rhar has quit [Read error: 110 (Connection timed out)]
noj has joined #ocaml
jeddhaberstro has quit [Client Quit]
caligula_ has joined #ocaml
caligula has quit [Read error: 60 (Operation timed out)]
peddie has joined #ocaml
peddie_ has quit [Read error: 110 (Connection timed out)]
poucet has quit [Read error: 60 (Operation timed out)]
poucet has joined #ocaml
smimou has quit [Read error: 110 (Connection timed out)]
smimou has joined #ocaml
verte has quit ["~~~ Crash in JIT!"]
<kaustuv> Excellent, 3.11.1 is now in debian testing.
mjs22 has joined #ocaml
mishok13 has joined #ocaml
mjs22 has quit []
rwmjones-afk is now known as rwmjones
eevar2 has joined #ocaml
<kaustuv> rwmjones: re your blog post about internals, it might be worth noting that it's <caml/mlvalues.h> not <mlvalues.h>
<rwmjones> kaustuv, ok
th5 has joined #ocaml
maskd has quit [SendQ exceeded]
Jedai has joined #ocaml
filp has joined #ocaml
naufraghi has joined #ocaml
julm has quit [Read error: 60 (Operation timed out)]
julm has joined #ocaml
Cromulent has joined #ocaml
tvn2009 has joined #ocaml
seafood has quit []
tvn2009 has quit [Remote closed the connection]
Modius has quit [Read error: 110 (Connection timed out)]
seafood has joined #ocaml
rwmjones is now known as rwmjones-afk
seafood has quit [Client Quit]
marteo has joined #ocaml
slash_ has joined #ocaml
hkBst has joined #ocaml
sramsay has joined #ocaml
seafood has joined #ocaml
seafood has quit []
maskd has joined #ocaml
_zack has joined #ocaml
ppsmimou has quit ["Leaving"]
_andre has joined #ocaml
Cromulent has quit []
Cromulent has joined #ocaml
Cromulent has quit []
jeddhaberstro has joined #ocaml
_zack has quit ["Leaving."]
thelema has joined #ocaml
willb has joined #ocaml
rob has joined #ocaml
<rob> hi, i'm learning Ocaml and stumbled upon the following example: http://de.wikipedia.org/wiki/OCaml#Beispiel_zur_funktionalen_Programmierung
Modius has joined #ocaml
<rob> can somebody explain to me how this works?
<thelema> rob: the function wiederhole takes two arguments
<thelema> the first it calls 'f'
<thelema> the second gets matches against the pattern "1 | n"
<thelema> *matched
<rob> ah ok, thats the first thing, i didn't get
<rob> where the number of args are definied
<rob> is it possible to have two arguments which are "pattern matched"?
<thelema> There's some technical things going on that make my first statement technically a lie.
<thelema> the way the syntax works, it's easiest to match just the last argument
<rob> ah ok
<thelema> if you want to match on multiple arguments, the normal way to do that is to:
<thelema> let f x y = match (x,y) with ...
<rob> ah
<bernardofpc> can't you just pattern-match and return a function ?
<bernardofpc> (well, sure match (x,y) is perhaps clearer in most cases)
<flx_> rob, btw, that is equivalent to: let f = fun x y -> match (x, y) with ... while the function-keyword is equal to fun _anon -> match _anon with ..
<thelema> bernardofpc: yes, you can, and that's what's really going on in the case of multiple arguments.
<bernardofpc> yes, because of currying, I think
<thelema> bernardofpc: something like that, yes.
<bernardofpc> ok ;-)
<rob> flx_, thx, i was wondering about this "function" keyword...
<rob> and what does this n -> (fun x -> (... do?
<thelema> rob: yes, [function] is like [fun _x -> match _x with]
<rob> what is the second -> operator for?
<thelema> if the second argument is != 1, it returns a function.
<flx_> you could have definitions like: let (@@) a b = a b let curry2 f a b = f (a, b) after which you could write: let f = curry2 @@ function (1, 2) -> 2 | _ -> 3 but really, do it thelema's way :-)
<bernardofpc> guess it makse a function f n x = blah
<thelema> that function takes a value [x] and calculates [(wiederhole f (n-1)) (f x)]
<flx_> rob, -> simply separates the arguments frmo the function body, ie. (fun x -> x) is a function that simply returns the argument
<rob> hm, ok
willb has quit ["Leaving"]
<thelema> rob: try evaluating the example use of wirderhole by hand.
jimmyb2187 has joined #ocaml
<thelema> maybe then you'll be able to characterize what it does in natural language. (or maybe not)
<bernardofpc> something like that may be done for Ackerman's function also ?
<bernardofpc> (anogher good
<rob> thelema: yes, i'm trying to after i understand the syntax now :)
bombshelter13_ has joined #ocaml
julm_ has joined #ocaml
Narrenschiff has joined #ocaml
<rob> *sigh*, i'm still not getting it :|
<rob> what does this mean? (wiederhole f (n-1)) (f x)
<thelema> wiederhole returns a function
<rob> and this function gets (f x) as a parameter
<thelema> (f x) returns a value
<thelema> yes, apply that function to the value
<rob> ah :)
<thelema> not something you see in other languages.
<thelema> especially not as concise as this.
<rob> nope, that's why i'm interested in these functional languages
<rob> but it's kinda of a totally different approach
<rob> than the classical stuff like C, c++, java, perl, php, ...
<thelema> yup.
<thelema> it changes your mind, learning this style
julm has quit [Read error: 110 (Connection timed out)]
Jedai has quit [Read error: 104 (Connection reset by peer)]
Jedai has joined #ocaml
flx__ has joined #ocaml
flx_ has quit [Read error: 104 (Connection reset by peer)]
dabd has joined #ocaml
_zack has joined #ocaml
rob is now known as rob_afk
rwmjones-afk has quit [Read error: 113 (No route to host)]
Jedai has quit [Connection timed out]
rob_afk is now known as rob
amuck_ has joined #ocaml
rwmjones has joined #ocaml
filp has quit [Operation timed out]
filp has joined #ocaml
flx__ is now known as flux
<thelema> great.
<rob> after having sth to eat :)
<rob> i tried to interpret the recursion of (wiederhole (fun x -> x + 2) 3) 1;;
<rob> this is what i have come up with:
<rob> 1. (wiederhole (fun x -> x + 2) 3) 1;;
<rob> 2. (wiederhole (fun x -> x + 2) 2) (1+2);;
<rob> 3. (wiederhole (fun x -> x + 2) 1) ((1+2)+2);;
<rob> 4. (fun x -> x + 2) ((1+2)+2);;
<rob> 5. ((1+2)+2) + 2;;
<th5> tada !
<rob> :) does this look correct?
<th5> i think so - this is a non-trivial example
<th5> notice that the type of weid is : ('a -> 'a) -> int -> ('a -> 'a)
<th5> so the number is really for how many times to apply the function again
<rob> hm
<rob> my toplevel says:
<rob> val wiederhole : ('a -> 'a) -> int -> 'a -> 'a = <fun>
<th5> same thing
<th5> but its easier for me to think about it as a function that produces a function
<rob> yep, me too
<th5> a -> a -> a is the same as a -> ( a -> a )
<th5> but not (a -> a ) -> a
<rob> ah ok
<rob> so it's left-to-right associative? or how is that called?
<thelema> it's right associative
<rob> ops
julm_ has quit [Remote closed the connection]
<rob> ah, like the = in C
<thelema> yes.
<rob> thx for the help!
rob is now known as rob_afk
<th5> mess around with the function giving a different f - for example (wiederhole (fun s -> s ^ " x") 3 ) "y"
rob_afk is now known as rob
<rob> yeah, it repeats the function as often as you specified in the 2nd argument
<rob> wiederhole (german for repeat)
<rob> the argument supplied to the function that is returned by wiederhole is used as the initial value
julm has joined #ocaml
Submarine has joined #ocaml
maskd has quit [Read error: 113 (No route to host)]
willb has joined #ocaml
julm has quit [Read error: 60 (Operation timed out)]
<rob> this is how the example would look like in C: http://pastebin.com/d62a8075f
<rob> IMHO it's more readable
<rob> of course the Ocaml code is more generic, since it can use other types (than integers) as well
<rob> you probably need C++ templates to implement that or (unsafe) void pointers in C
willb has quit ["Leaving"]
willb has joined #ocaml
willb has quit [Read error: 104 (Connection reset by peer)]
willb has joined #ocaml
willb has quit [Client Quit]
willb has joined #ocaml
holgr has quit [Read error: 110 (Connection timed out)]
<rob> ok, i'm out, thx for the help @all
julm has joined #ocaml
<th5> how about: let rec repeat f x p = if (x == 1) then f p else f (repeat f (x-1) p)
<th5> oops
<th5> left
<th5> see you
th5 has quit []
eevar2 has quit [Remote closed the connection]
willb has quit ["Leaving"]
willb has joined #ocaml
rob has left #ocaml []
hcarty has joined #ocaml
psnively has joined #ocaml
_zack has quit ["Leaving."]
julm has quit [Read error: 110 (Connection timed out)]
kaustuv has left #ocaml []
willb1 has joined #ocaml
willb1 has quit [Read error: 104 (Connection reset by peer)]
julm has joined #ocaml
bluestorm has joined #ocaml
naufraghi has quit []
Jedai has joined #ocaml
filp has quit ["Bye"]
julm has quit [Read error: 110 (Connection timed out)]
Submarine has quit [Remote closed the connection]
smimou has quit ["bli"]
jeddhaberstro has quit [Client Quit]
psnively has quit []
Narrenschiff has quit []
psnively has joined #ocaml
caligula_ has quit [Read error: 113 (No route to host)]
julm has joined #ocaml
<thelema> let rec repeat f acc n = if n = 0 then acc else repeat f (f acc) (n-1)
<bluestorm> let repeat f acc n = Array.fold_left f acc (Array.init n (fun i -> n - i))
<bluestorm> :-'
<thelema> blue: I don't think you can use fold_left on f
<thelema> repeat : ('a -> 'a) -> n -> 'a -> 'a
<bluestorm> ah, right
<bluestorm> in my repeat, f has access to the integer parameter as well
<thelema> yes, and I don't know why you want to give it n .. 1 as second parameter
<thelema> I guess so it could know what iteration it was running?
<bluestorm> well giving the integer parameter gives you basically primitive recursion
caligula has joined #ocaml
<bluestorm> wich is a concept wich has been used theoretically
<bluestorm> (a third way to computability, instead of lambda calculus and Turing machines)
caligula has quit [Client Quit]
<bluestorm> but yes, in that case the integer parameter is ugly and breaks abstraction
<thelema> you could hide it, by [Array.fold_left (fun x n -> f x) ...]
<bluestorm> of course
<bluestorm> but at some point the recursive solution, besides being more efficient, also becomes easier to read
caligula has joined #ocaml
<thelema> "the" recursive solution? earlier attempts at a recurisve solution looked as ugly as this:
<thelema> let rec wiederhole f = function | 1 -> f | n -> (fun x -> (wiederhole f (n - 1)) (f x));;
<thelema> (from the german wikipedia entry on ocaml)
<bluestorm> hm
<bluestorm> i don't find it ugly
<bluestorm> (think ? is "find" correct in that context ?)
<thelema> I find it much harder to read and understand than my version
<bluestorm> it's closer to the mathematical definition
<thelema> "find" is appropriate
<bluestorm> so might be better for a mathematics-minded reader
<thelema> point-free notation didn't help me figure it out.
<thelema> knowing what it is, I can verify that it's correct, but when presented with it at first, I didn't immediately go "aha, it does ..."
<bluestorm> f^(0) = f, f^(n) : x -> f^(n-1)(f(x)) (or non tail-recursive f(f^(n-1)(x)))
<thelema> the extra (fun x -> ...) threw me off the trail of understanding
<thelema> better to just take x as a parameter in the first place
<thelema> although more efficient this way in the n=1 case
psnively has quit []
caligula has quit ["Konversation terminated!"]
ulfdoz has joined #ocaml
caligula has joined #ocaml
mishok13 has quit [Read error: 110 (Connection timed out)]
Ori_B has quit [Read error: 54 (Connection reset by peer)]
Ori_B_ has joined #ocaml
Ori_B_ is now known as Ori_B
_zack has joined #ocaml
marteo has quit [Read error: 145 (Connection timed out)]
marteo has joined #ocaml
_zack has quit ["Leaving."]
<bluestorm> "write f : int -> int such that f(f(n)) = -n"
<bluestorm> let f x = if Obj.is_int (Obj.repr x) then Obj.magic (fun unit -> -x) else (Obj.magic x () : int);;
marteo has quit ["Debian GNU/Hurd is Good."]
marteo has joined #ocaml
willb has quit ["Leaving"]
willb has joined #ocaml
marteo has quit ["Debian GNU/Hurd is Good."]
Demitar has quit ["Ex-Chat"]
hto has joined #ocaml
bombshelter13_ has quit []
_andre has quit ["leaving"]
bluestorm has quit ["Leaving"]
jeddhaberstro has joined #ocaml
hto has quit ["Lost terminal"]
hto has joined #ocaml
ulfdoz has quit [Read error: 60 (Operation timed out)]
hto has quit ["leaving"]
hto has joined #ocaml
hto has quit [Client Quit]
hto has joined #ocaml
hto has quit [Client Quit]
hto has joined #ocaml
hto has quit [Client Quit]
hto has joined #ocaml
marteo has joined #ocaml
smimou has joined #ocaml
marteo has quit ["Debian GNU/Hurd is Good."]
maskd has joined #ocaml
willb has quit [Read error: 110 (Connection timed out)]
hkBst has quit [Read error: 104 (Connection reset by peer)]
BiDOrD has quit [Read error: 60 (Operation timed out)]
smimou has quit [Read error: 104 (Connection reset by peer)]
haelix has joined #ocaml
amuck_ has quit []
BiDOrD has joined #ocaml
marteo has joined #ocaml
amuck_ has joined #ocaml
amuck_ has quit [Remote closed the connection]
marteo has quit ["Debian GNU/Hurd is Good."]
M| has quit ["Never look down on someone unless you're helping them up."]