cjeris changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/
david_koontz has quit ["Leaving"]
shawn has quit [Read error: 113 (No route to host)]
a-priori_ is now known as a-priori
Submarine has quit [Remote closed the connection]
skal__ has joined #ocaml
skal_ has quit [Read error: 110 (Connection timed out)]
<tsuyoshi> anyone here use cduce?
hcarty has quit ["leaving"]
rturner has quit ["Ex-Chat"]
<twobitsprite> /join #gnome
<twobitsprite> er
Smerdyakov has quit ["Leaving"]
Smerdyakov has joined #ocaml
Mr_Awesome has joined #ocaml
twobitsprite has quit [Remote closed the connection]
twobitsprite has joined #ocaml
skal__ has quit [Read error: 110 (Connection timed out)]
G_ is now known as G
Mr_Awesome has quit ["...and the Awesome level drops"]
Smerdyakov has quit ["Leaving"]
G_ has joined #ocaml
benny has joined #ocaml
G has quit [Read error: 110 (Connection timed out)]
screwt8 has quit [Remote closed the connection]
benny_ has quit [Read error: 60 (Operation timed out)]
slipstream-- has joined #ocaml
slipstream has quit [Read error: 60 (Operation timed out)]
screwt8 has joined #ocaml
skal has joined #ocaml
Amorphous has quit ["shutdown"]
jkeith has joined #ocaml
pedro_soc has joined #ocaml
Amorphous has joined #ocaml
G_ is now known as G
<pedro_soc> hi, can anyone show me a real or not trivial use of curried function ?
<pedro_soc> i know, what its and how to use it. But i don't imagine any sample of use.
<flux> simplest case: let strings = List.map string_of_int [1; 2; 3]
<flux> and very real-world I'd say
<flux> although I suppose that could be viewed as not being currying, but function passing.. hmm..
<flux> but often you want to do something similar, but provide some parameters in between
<flux> I suppose that was trivial :)
<pedro_soc> but, where is the curried there ?
<flux> it could be viewed as being the same as List.map (fun v -> string_of_int v) [1; 2; 3]
<pedro_soc> ok, i see.
<flux> I found one pattern I've used, but I'm not sure if that's convincing..
<flux> it's basically involves having a bunch of definitions such as let foo a b c () = .., and the user is expected to pass them to a function as parameters without the last application
<flux> do_stuff (foo 1 2 3)
<mrvn> let int_skalar_mult m = let m = float_of_int m in function (x, y, z) -> (m *. x, m *. y, m *. z)
<mrvn> let inc = (+) 1
<flux> I suppose these are simple cases involving only one argument
<mrvn> well, you need at least 2 for currying
<flux> I'm quite certain I've used it in other ways too :)
<flux> but currying feels very natural to me
<flux> a semantic grep would be nice. "find all function applications that return a function"
<pedro_soc> yes, i have code the simplest example that i find out, but i dont feel comfortable carrying. That the reason i looking for more examples.
<mrvn> List.map (( + ) 1) [1;2;3] is the simplest I can think of.
<flux> I suppose the most cases involve returning a function with one argument
<mrvn> The next best thing would be a callback
<mrvn> I always hate that you can't just do 'type callback = unit -> callback'
<pedro_soc> yes, thats the point i was trying today to write a function that iterate over a list and apply to each element a curried function.
<flux> mrvn, -rectypes?-)
<mrvn> yeah, but that has side effects
<pedro_soc> um side effects ??
<flux> methinks sometimes being able to curry is just by luck
<flux> the arguments happen to be in the proper order. and sometimes you have bad luck.
<flux> but that can sometimes be gotten around with labeled arguments
<mrvn> pedro_soc: it changes the type detection
<mrvn> flux: sometimes you have to go back and sort arguments differently
<mrvn> or use closures
<flux> or labeled arguments: let div ~a ~b = a / b
<mrvn> fun x1 x2 = fn x2 x1
<flux> actually div is a keyword, so that cannot be used
<flux> but after that you can do let f = div_l ~b:42
<flux> I suppose it wouldn't be a bad habbit to most of the time used labeled arguments
<mrvn> But do labels actually do currying?
<flux> hm, yes, maybe it's technically something else
<flux> but it's similar
<flux> because a function that has had one label applied to it will return a function with one less labels
<mrvn> But it will never execute code will it?
ppsmimou has quit ["Leaving"]
<flux> not until all the arguments are filled in
ppsmimou has joined #ocaml
<flux> heh, this is fun/strange: let f = fun ~a -> Printf.printf "Hello\n%!"; fun ~b -> a + b;;
<flux> fun ~b:42 will not output the string
<flux> fun ~b:42 ~a:42 will
<mrvn> One of the big effects of having functions as values is that you can eat the first few arguments of a function, do some calculations and return a function that has those computed values.
<flux> so it does some type magic
<mrvn> Like compiling a regexp for regexp matching.
<flux> it apparently applies the values as far as it can, as f ~a:42 will produce "Hello"
<mrvn> You can actualy do ~x across multiple "fun" statements? wow.
<mrvn> Then it is normal currying
<pedro_soc> i have another question : when i curried a function i always curried the first argument, its posible to curried other argument.
<pedro_soc> i mean i wrote this example, but the dec function didnt work.
<pedro_soc> an its because the argument its not in the correct order, can i specify that i want to curry the Y argument?
<flux> pedro_soc, you cannot, except by labeling arguments. another possibility is to have let flip f x y = f y x
<flux> then you can type let dec = flip minus 1
<pedro_soc> ok. How can i use labeled arguments?
<flux> tööttööt kuuluu ulkoa
<flux> joku tai tunata valoissa
<flux> whops, wrong channel :)
mikeX has joined #ocaml
Sparkles has joined #ocaml
benny99 has joined #ocaml
benny99 has left #ocaml []
benny99 has joined #ocaml
benny99 has left #ocaml []
Sparkles has quit []
<flux> pedro_soc, ah-ha! an actual use case: List.iter (Hashtbl.remove table) remove_these
<pedro_soc> umm, Can you show me a little bit more ?
Sparkles has joined #ocaml
hcarty has joined #ocaml
<flux> let removes = Hashtbl.fold (fun key (_, r) l -> if !r < limit then key::l else l) surfaces [] in List.iter (Hashtbl.remove surfaces) removes
<flux> (I don't want to remove stuff from hash while iterating. it might be bring bad karma.
<flux> )
Sparkles_ has joined #ocaml
Sparkles has quit [Read error: 110 (Connection timed out)]
Sparkles_ has quit [Read error: 110 (Connection timed out)]
Sparkles has joined #ocaml
Sparkles has quit []
Sparkles has joined #ocaml
zmdkrbou has quit ["wapff update"]
zmdkrbou has joined #ocaml
Sparkles has quit []
benny99 has joined #ocaml
<benny99> hm, this channel is clean huh? No flaming, no links -- but also no discussions huh ?
<hcarty> benny99: If you start a discussion, people may join in. Things tend to be quiet around here until someone asks a question.
<benny99> hcarty: ok, so I start with an easy one
<benny99> *with an easy question...
<benny99> How could I acess for example the second member of an arbitrary list ?
<twobitsprite> what would be the best way to implement a binary protocol in ocaml... I've tried useing output_value with int32's, but it seems to still send quite a bit of garbage...
<benny99> twobitsprite: there's one bit reserved for internal purposes in ocaml huh ?
<benny99> Always ending a question with "huh" is strange huh ?
<hcarty> benny99: I don't know if this is the best way, but: List.hd (List.hd l)
<hcarty> Sorry, I mean List.hd (List.tl l)
pango_ has quit [Remote closed the connection]
<benny99> hcarty: you meant List.tl (List.hd l) ;P
<benny99> but it's ok for now
<benny99> no, yours was correct...
<benny99> sorry :o
<hcarty> or List.nth l 2
<hcarty> benny99: Not a problem :-)
<benny99> List.nth is better :)
<benny99> thank you
<benny99> is there also a way to look up that thingies ?
<hcarty> Sure
<benny99> hm, where :Z ?
<hcarty> That has all(?) of the standard lib docs
<benny99> argh, I only found that tiny tutorial on that page :|
<benny99> thanks
pango_ has joined #ocaml
<hcarty> http://caml.inria.fr/pub/docs/manual-ocaml/ is the whole thing, but the libref link is the one I personally use most often
<benny99> hcarty: yeah, have been thre, but I didn't find libref :Z
<benny99> searched for reference...
<benny99> Something different, is there a neat way to implement an insertion sort with tail recursion ?
<hcarty> I can't help with that one, but someone may have an answer - sometimes it can take a few hours, but the answers are usually quite good when they come.
<benny99> so I hope someone listens to me ;)
<mrvn> hcarty: you can't insert into a list so you have to always copy the full list. List.fold_left is your best option then.
<hcarty> mrvn: benny99 had the question, but thanks
<hcarty> benny99: But that's a good point - lists are immutable in OCaml, while arrays are not
<benny99> hcarty: hm... maybe I should try to implement a merge sort or something, because insertion sort is not really the sort for functional languages ?
<benny99> hcarty: oh
<tsuyoshi> there are already sort functions in the standard library
<tsuyoshi> don't know why you'd want to write another one
<benny99> tsuyoshi: learning
mrvn has quit [Read error: 60 (Operation timed out)]
<benny99> well, I'm gone then too :)
<benny99> bye
Smerdyakov has joined #ocaml
benny99 has left #ocaml []
postalchris has joined #ocaml
mrvn has joined #ocaml
pedro_ has joined #ocaml
pedro_soc has quit [Read error: 60 (Operation timed out)]
<mrvn> One reason to reimplement merge sort is to make it tail recursive
jkeith has quit [Read error: 110 (Connection timed out)]
dark_light has quit [Operation timed out]
joshcryer has quit [Read error: 104 (Connection reset by peer)]
dbueno has joined #ocaml
<dbueno> I'm using ocamlscript for the first time, and getting this error when I run 'ocamlscript myscript.ml': Unbound value OCaml.packs
<dbueno> Anyone willing to help?
<mrvn> You wrote a module named OCaml?
<dbueno> mrvn: According to the documentation of ocamlscript, that is the module you refer to to configure stuff.
<dbueno> However, I just now tried a few examples with ocamlscript, and my error is gone. *shrug*
<mrvn> never used it
twobitsprite has quit ["Lost terminal"]
dbueno has quit ["This computer has gone to sleep"]
bluestorm_ has joined #ocaml
<tsuyoshi> huh.. doesn't extlib have tail recursive sort
shawn has joined #ocaml
<tsuyoshi> oh it doesn't
TaXules has quit [Read error: 104 (Connection reset by peer)]
pedro__ has joined #ocaml
slipstream-- has quit [Read error: 54 (Connection reset by peer)]
slipstream has joined #ocaml
pedro_ has quit [Read error: 113 (No route to host)]
Submarine has joined #ocaml
bluestorm_ has quit ["Konversation terminated!"]
Smerdyakov has quit ["Leaving"]
vorago has quit [Read error: 110 (Connection timed out)]
joshcryer has joined #ocaml
hcarty has quit ["leaving"]
Sparkles has joined #ocaml
hcarty has joined #ocaml
Sparkles has quit []
Submarine has quit [Remote closed the connection]
[ElPhIl] has joined #ocaml
vorago has joined #ocaml
Smerdyakov has joined #ocaml
[ElPhIl] has quit ["Leaving"]
pedro__ has quit ["Abandonando"]
postalchris has quit [Read error: 110 (Connection timed out)]
mikeX has quit ["leaving"]