<krumms>
effectively want to translate chord_map such that for an entry (n, [k1; k2; k3]), we generate entries in the resulting list that look like: [k1, n; k2, n; k3, n]
<krumms>
I'm a little disgusted that my code to generate that table of reverse mappings is longer than what it would be if I just copied it over by hand :)
<krumms>
but I'm relatively new to ocaml ... not entirely sure what to try next
<flux>
krumms, atleast the pattern let rec .. chords = .. let a = List.hd chords.. let b = List.tl chords.. could be replaced with let rec .. (a::b) ..
<krumms>
flux, that's a start - thank you :)
<flux>
so that'll cut 4 lines and a useless name
<flux>
also you appear to use a non-tail-recursion elimination pattern
<flux>
so for better efficiency you could replace the let new_result = a @ [b] with b::a and in the [] -> new_result do [] -> List.rev new_result
<flux>
hm, infact, isn't chord_sequence a lot like List.map?
<flux>
List.map (fun value -> (chord, value)) chords
<flux>
chord_sequence fails with an empty list anyway; the match on empty list should be done earlier
<flux>
construct_chord_map appears to follow the same pattern
<krumms>
thanks heaps flux, post a new version shortly
<bluestorm_>
hm
<bluestorm_>
so you choosed a guitar program as a pratical topic ?
<bluestorm_>
hm flux
yminsky has quit []
<bluestorm_>
« let rec .. (a::b) .. »
<krumms>
bluestorm_: nope, this is a personal project :)
<bluestorm_>
aren't those kind of non-exhaustive matches forbidden by the revised syntax for example ?
<bluestorm_>
i like to write let [a';b';c';d'] = List.map foo [a; b; c; d] very much, but i feel guilty at the same time
<flux>
bluestorm_, well, the function did unconditional List.tl anyway
<flux>
but yeah, the compiler does produce diagnostics on that case
<flux>
sometimes it annoys me :)
<flux>
but if the functions can be replaced with a List.map, all the better..
<bluestorm_>
my problem is not really warnings (i guess they might be turned off), but the feeling i may be doing something semantically dubious ^^
<bluestorm_>
krumms:
<bluestorm_>
[a; b; c; d] very much, but i feel guilty at the same time
<bluestorm_>
[15:11:59] <flux> bluestorm_, well, the function did unconditional List
<pango>
(* like this *) let inv2 chords = List.fold_left (fun acc (num, notes) -> List.fold_left (fun acc note -> (note, num) :: acc) acc notes) [] chords ;;
<xavierbot>
val inv2 : ('a * 'b list) list -> ('b * 'a) list = <fun>
<bluestorm_>
pango: i find the flatten version more straightforward
<bluestorm_>
and GHC could optimise it away :-°
<flux>
pango, wouldn't you like to use fold_right to preserve the order
<flux>
anyway, I would prefer the version with flatten, IMO it's easier to see what's going on. even some of the intermediate functions could be a good idea.
<pango>
depends whether the order matter. List.fold_left in tailrec
<pango>
s/in/is/
<bluestorm_>
i don't think the order matters here
<bluestorm_>
as he seems to consider a num <-> chord relation
b00t has quit ["Leaving"]
<flux>
the original code seemed to go into some lengths to maintain the order
<flux>
(the list concatenation namely)
rwmjones_ has quit ["This computer has gone to sleep"]
pango has quit [Remote closed the connection]
pango has joined #ocaml
mnemonic has quit ["leaving"]
pantsd has quit ["Leaving."]
Smerdyakov has joined #ocaml
yminsky has joined #ocaml
fy__ has joined #ocaml
yminsky has quit []
love-pingoo has quit ["Connection reset by pear"]
noteventime has quit [Remote closed the connection]
noteventime has joined #ocaml
jlouis_ has joined #ocaml
jlouis has quit [Read error: 110 (Connection timed out)]
Mr_Awesome has joined #ocaml
rwmjones_ has joined #ocaml
rwmjones_ has quit [Client Quit]
brothers has quit [Read error: 104 (Connection reset by peer)]
krumms_ has joined #ocaml
buluca has quit [Read error: 113 (No route to host)]
krumms-ZZZ has quit [Read error: 110 (Connection timed out)]
piggybox_ has joined #ocaml
minciue has quit [Read error: 110 (Connection timed out)]
piggybox has quit [Nick collision from services.]
piggybox_ is now known as piggybox
slipstream-- has joined #ocaml
slipstream has quit [Read error: 110 (Connection timed out)]
minciue has joined #ocaml
noteventime has quit [Remote closed the connection]
noteventime has joined #ocaml
brothers has joined #ocaml
ygrek has quit ["Leaving"]
seafoodX has joined #ocaml
_blackdog has joined #ocaml
_blackdog has left #ocaml []
buluca has joined #ocaml
mnemonic has joined #ocaml
qwwqe has joined #ocaml
jlouis_ has quit [Remote closed the connection]
jlouis has joined #ocaml
smimou has joined #ocaml
buluca has quit ["Leaving."]
seafoodX has quit []
buluca has joined #ocaml
kig has quit [Read error: 110 (Connection timed out)]
leo037 has quit ["c'est pas faux"]
smimou has quit ["bli"]
fax has joined #ocaml
<fax>
hello
<Mr_Awesome>
hi
krumms has joined #ocaml
<fax>
I was wondering what/if anything people use to write GUI programs on mac with Ocaml?
<Mr_Awesome>
well, could use tcl/tk
<fax>
you would embed tcl in Ocaml and then use the tk lib from in that way?
<Smerdyakov>
Isn't there already an OCaml library that figures that out in its implementation, freeing you from deciding?
<bluestorm_>
it's older (but i don't think a lot of things changed since), but maybe more "user-friendly"
<bluestorm_>
(and less complete, of course)
<fax>
I would like one which can call C functions which pass/return structs a values
<bluestorm_>
both these document describe the official, out-of-box Caml-to-C interface
<fax>
I can't tell from this documentation.. anyone know if the C interface lets you call C functions which take as parameters or return structs as values?
<fax>
in Ocaml how can you call the stdlib function div_t div(int num, int denom); for example?