Yurik changed the topic of #ocaml to: http://icfpcontest.cse.ogi.edu/ -- OCaml wins | http://www.ocaml.org/ | http://caml.inria.fr/oreilly-book/ | http://icfp2002.cs.brown.edu/ | SWIG now supports OCaml| Early releases of OCamlBDB and OCamlGettext are available
mrvn_ has quit [Read error: 110 (Connection timed out)]
matkor has quit [Remote closed the connection]
<mellum> Hmm, I want a funktion that takes two 'a list lists, and returns a list with all concatenations from them. Any suggestions on how to do that elegantly?
<whee> all possible combinations?
<mellum> Yes.
<mellum> Actually, they need to be sorted too, but that's for another function to do I guess
<whee> there's a relatively easy way, but I can't remember it :)
<mellum> Damn :)
<whee> you cnan probably do it with a few fold_lefts
<whee> or a couple, even
<mellum> Hm, I was trying List.map
<whee> it's really easy to do in a language with list comprehensions, which ocaml doesn't have :\
<mellum> Well, I already changed language once :)
<mellum> Hm, I think it gets easier if I pass the result around
<mellum> not quite as pretty, though
<whee> the haskell version with list comprehensions is something like combinations (x:xs) = [(y:ys) | y <-x, ys <- combinations xs]
<whee> you could try translating that :)
<mellum> grr
<whee> it probably does end up turning into a few fold_lefts
<whee> maybe a map thrown in there
<whee> I don't know :)
<whee> it'd be nice if they were added to the language, heh
<mellum> Well, I can do it with using @'s, but I would rather have it tail recursive...
<mellum> Oh well, this part is going to change later anyway, so I give up for now
<whee> you could prepend to the list instead
<whee> then reverse at the end if order really matters
<mellum> I don't see how
<mellum> Currently I got
<mellum> let rec concat ll1 ll2 =
<mellum> match ll1 with
<mellum> [] -> ll2
<mellum> | l1 :: l1s ->
<mellum> (List.map (fun l -> l1 @ l) ll2) @ concat l1s ll2
<whee> hmm
<whee> what's the function behind ::? :|
<mellum> (::) of course :)
<whee> that doesn't work
<emu> (:
<emu> :-) ?
<whee> it's a syntax error; I don't know how else to reference operators
<mellum> Oh, wait, (::) is magic
<emu> EMOTRAN
<mellum> because it can also be used in matchings
<whee> bah :|
<whee> oh, well that didn't work
<whee> heh
<whee> I ended up doing the power set I think :)
<mellum> Keep that, might be handy sometimes, too :)
<mrvn> mellum: ever tried val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list ?
<mrvn> or List.rev (List.rev_map2 f a b)
<mrvn> for tail-recursion
<mellum> mrvn: that matches the list pairwise, but I want all possible pairs
<mrvn> mellum: List.fold_leftlet combine l1 l2 =
<mrvn> let l =
<mrvn> List.fold_left
<mrvn> (fun res w1 ->
<mrvn> List.fold_left
<mrvn> (fun res w2 -> (w1@w2)::res)
<mrvn> res l2)
<mrvn> [] l1
<mrvn> in
<mrvn> List.rev l;;
<mellum> Hmm, let me try
<mrvn> let l1 = [['0']; ['1']];;
<mrvn> combine l1 l1;;
<mrvn> - : char list list = [['0'; '0']; ['0'; '1']; ['1'; '0']; ['1'; '1']]
<mellum> Looks good
<mrvn> Still an @ in there
<mrvn> But it keeps the sorting if both lists are sorted before
<mellum> the outer sorting is irrelevant. The inner lists need to besorted
<mellum> so I need a special function for the @ anyway
<mellum> mrvn: If you're bored, try writing a function that merges two descendingly sorted lists into an ascendingly sorted one :)
<whee> can't you just reverse both and merge?
<mellum> whee: aw, that's lame
<mellum> although I probably still do it because it's shorter
<mrvn> mellum: just remove the extra List.rev in the code above
<mellum> mrvn: No, it's for the inner lists
<mellum> Hmm, does it matter performance-wise whether I leave off the arguments to l?
<mrvn> l?
<mellum> Yes, the final call of the loop.
<mrvn> come again
<mellum> Oh, never mind.
<mrvn> let rev_wappend (w:'a list) (l:'a list list) =
<mrvn> List.fold_left
<mrvn> (fun l x -> List.map (fun w -> x::w) l)
<mrvn> (List.map List.rev l) w;;
<mrvn> let combine l1 l2 =
<mrvn> let l =
<mrvn> List.fold_left
<mrvn> (fun res w1 -> rev_wappend w1 l2@res)
<mrvn> [] l1
<mrvn> in
<mrvn> List.rev l;;
<mrvn> let l1 = [['b';'a']; ['d';'c']; ['f';'e']; ['h';'g']];;
<mrvn> let l2 = [['1';'0']; ['3';'2']; ['5';'4']; ['7';'6']];;
<mrvn> combine l1 l2;;
<mrvn> [['a'; 'b'; '6'; '7']; ['a'; 'b'; '4'; '5']; ['a'; 'b'; '2'; '3'];
<mrvn> ['a'; 'b'; '0'; '1']; ['c'; 'd'; '6'; '7']; ['c'; 'd'; '4'; '5'];
<mrvn> ...
<mrvn> n8
__DL__ has joined #ocaml
Sonarman has joined #ocaml
Kinners has joined #ocaml
__DL__ has quit ["Client Exiting"]
det has joined #ocaml
jemfinch`` has joined #ocaml
jemfinch`` is now known as jemfinch
lament has quit ["Did you know that God's name is ERIS, and that He is a girl?"]
Kinners has left #ocaml []
skylan has quit ["bbiab"]
Sonarman has quit ["Lost terminal"]
skylan has joined #ocaml
mattam has joined #ocaml
skylan has quit [leguin.freenode.net irc.freenode.net]
mellum has quit [leguin.freenode.net irc.freenode.net]
rox has quit [leguin.freenode.net irc.freenode.net]
emu has quit [leguin.freenode.net irc.freenode.net]
mellum has joined #ocaml
emu has joined #ocaml
skylan has joined #ocaml
rox has joined #ocaml
lament has joined #ocaml
Rhaaw has joined #ocaml
<Rhaaw> What's the best place to start learing ocaml ?
<lament> Probably the channel topic.
<Rhaaw> That O'Reilly book ?
<Rhaaw> The thing is, I don't want to start with something as bad for ocaml as Sams teach yourself C++ in...
<lament> i actually meant the ocaml website :)
lament has quit ["Did you know that God's name is ERIS, and that He is a girl?"]
gehel has joined #ocaml
gehel is now known as gl
TachYon26 has joined #ocaml
<emu> best place to leer at camels would be the middle east i say
gl has quit ["Lost terminal"]
det has quit [Remote closed the connection]
jemfinch has quit [Read error: 104 (Connection reset by peer)]
jemfinch has joined #ocaml
foxster has quit [Connection reset by peer]
xkb has joined #ocaml
xkb has quit ["Killed by frash (Requested by panasync)"]
xkb has joined #ocaml
foxster has joined #ocaml
Rhaaw has quit [Read error: 110 (Connection timed out)]
Rhaaw has joined #ocaml
det has joined #ocaml
det has quit [Client Quit]
det has joined #ocaml
det has quit [Client Quit]
mellum_ has joined #ocaml
physarum has joined #ocaml
mellum has quit [Read error: 110 (Connection timed out)]
mrvn_ has joined #ocaml
mrvn has quit [Read error: 60 (Operation timed out)]
foxster has quit [Read error: 60 (Operation timed out)]
det has joined #ocaml
jemfinch has quit [Read error: 54 (Connection reset by peer)]
det has quit [Remote closed the connection]
physarum has quit ["Client Exiting"]
merriam has quit [Excess Flood]
mattam has quit ["leaving"]
mrvn has joined #ocaml
mrvn_ has quit [Read error: 104 (Connection reset by peer)]
Dalroth has joined #ocaml
rox has left #ocaml []
polin8 has joined #ocaml
steele has joined #ocaml
<steele> hi
esabb has joined #ocaml
TachYon26 has quit [Remote closed the connection]
Rhaaw has left #ocaml []
foxster has joined #ocaml
mattam has joined #ocaml
mellum_ is now known as mellum
matkor has joined #ocaml
redcrosse has joined #ocaml
esabb has left #ocaml []
mattam_ has joined #ocaml
mattam has quit [Read error: 60 (Operation timed out)]
matkor has quit ["Client Exiting"]
gene9 has joined #ocaml
gene9 has quit [Client Quit]
Dalroth has quit []
mrvn has quit [Read error: 110 (Connection timed out)]
<whee> haha, daniel _did_ decide to completely stop working on camlp4
<whee> what a baby :)
redcrosse has quit []
jemfinch has joined #ocaml