flux changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | OCaml 4.01.0 http://bit.ly/1851A3R | http://www.ocaml.org | Public logs at http://tunes.org/~nef/logs/ocaml/
jpdeplaix has quit [Ping timeout: 272 seconds]
maufred has quit [Ping timeout: 272 seconds]
nikki93 has joined #ocaml
mfp has quit [Ping timeout: 256 seconds]
nikki93 has quit [Remote host closed the connection]
nikki93 has joined #ocaml
arquebus has joined #ocaml
steshaw has quit [Read error: Connection reset by peer]
Drup has quit [Quit: Leaving.]
madroach has quit [Ping timeout: 264 seconds]
madroach has joined #ocaml
talzeus_ has quit [Remote host closed the connection]
talzeus_ has joined #ocaml
csakatoku has joined #ocaml
shinnya has quit [Ping timeout: 248 seconds]
talzeus_ has quit [Ping timeout: 240 seconds]
nikki93 has quit [Remote host closed the connection]
boogie has quit [Remote host closed the connection]
zamn has joined #ocaml
<zamn> hi, can someone help me debug this syntax error I am receiving? http://pastebin.com/C190MjFp - On linle 6 i get: this expression has type 'a list but an expression was expected of type unit
<zamn> i can't seem to figure out what i'm doing wrong
talzeus_ has joined #ocaml
nikki93 has joined #ocaml
maufred has joined #ocaml
zamn has quit [Quit: leaving]
hmmh has joined #ocaml
jpdeplaix has joined #ocaml
strobegen has joined #ocaml
hmmh has quit [Quit: ...]
breakds has joined #ocaml
cesar_ has joined #ocaml
cesar_ is now known as Guest74984
boogie has joined #ocaml
Guest74984 has quit [Ping timeout: 246 seconds]
breakds has quit [Remote host closed the connection]
boogie has quit [Remote host closed the connection]
<nikki93> http://codepad.org/3xfipODt <-- fold_right written using fold_left
<nikki93> was experimenting with 'continuation passing' stuff using fold_left, thought this was cool
boogie has joined #ocaml
<nikki93> (thus this is also tail-recursive... grows on heap though because closures)
ollehar has quit [Ping timeout: 272 seconds]
justdit has joined #ocaml
arquebus has quit [Quit: Konversation terminated!]
derek_c has joined #ocaml
justdit has quit [Remote host closed the connection]
justdit has joined #ocaml
zpe has joined #ocaml
zpe has quit [Ping timeout: 246 seconds]
justdit has quit [Read error: Connection reset by peer]
justdit has joined #ocaml
Simn has joined #ocaml
ulfdoz has joined #ocaml
gour has joined #ocaml
yacks has joined #ocaml
ulfdoz has quit [Ping timeout: 246 seconds]
mcclurmc has quit [Ping timeout: 256 seconds]
ulfdoz has joined #ocaml
csakatok_ has joined #ocaml
csakatoku has quit [Ping timeout: 248 seconds]
justdit_ has joined #ocaml
justdit has quit [Ping timeout: 264 seconds]
justdit_ has quit [Read error: Connection reset by peer]
paolooo has joined #ocaml
justdit has joined #ocaml
boogie has quit [Remote host closed the connection]
cesar_ has joined #ocaml
cesar_ is now known as Guest21386
csakatok_ has quit [Remote host closed the connection]
ulfdoz has quit [Ping timeout: 246 seconds]
Guest21386 has quit [Remote host closed the connection]
Neros has quit [Ping timeout: 240 seconds]
tobiasBora has joined #ocaml
tobiasBora has quit [Client Quit]
Yoric has joined #ocaml
q66 has joined #ocaml
thomasga has joined #ocaml
csakatoku has joined #ocaml
csakatoku has quit [Remote host closed the connection]
thomasga1 has joined #ocaml
thomasga has quit [Read error: Connection reset by peer]
csakatoku has joined #ocaml
thomasga1 has quit [Ping timeout: 252 seconds]
ttamttam has joined #ocaml
zpe has joined #ocaml
nisstyre has quit [Read error: Connection timed out]
zpe has quit [Read error: Connection reset by peer]
zpe has joined #ocaml
mika1 has joined #ocaml
derek_c has quit [Ping timeout: 246 seconds]
derek_c has joined #ocaml
justdit_ has joined #ocaml
justdit has quit [Read error: Connection reset by peer]
skchrko has quit [Quit: Leaving]
yezariaely has joined #ocaml
q66 has quit [Ping timeout: 268 seconds]
nikki93 has quit [Remote host closed the connection]
ggole has joined #ocaml
yacks has quit [Quit: Leaving]
talzeus_ has quit [Read error: Connection reset by peer]
talzeus_ has joined #ocaml
rwmjones has quit [Ping timeout: 264 seconds]
Yoric has quit [Ping timeout: 248 seconds]
radditz has joined #ocaml
rwmjones has joined #ocaml
q66 has joined #ocaml
Kakadu has joined #ocaml
justdit_ has quit [Read error: Connection reset by peer]
Kakadu has quit [Ping timeout: 272 seconds]
mort___ has joined #ocaml
Kakadu has joined #ocaml
bnoordhuis has joined #ocaml
mfp has joined #ocaml
Gabuzo4426 has joined #ocaml
AltGr has joined #ocaml
Gabuzo4426 has quit [Client Quit]
derek_c has quit [Quit: Lost terminal]
<radditz> HI
bnoordhuis has quit [Ping timeout: 272 seconds]
bnoordhuis has joined #ocaml
ocp has joined #ocaml
avsm has joined #ocaml
Yoric has joined #ocaml
wolfnn has joined #ocaml
skchrko has joined #ocaml
<jyeo> i am trying to change the order that ocamlbuild generates the camlp4 command line argument. is there anyway to do that?
<jyeo> e.g camlp4 'pa_X.cma' 'pa_Y.cma' myfile.ml
<jyeo> gets changed to camlp4 'pa_Y.cma' pa_X.cma' myfile.ml
<jyeo> changing the order in the _tags file isn't working for me :-/
<radditz> jyeo: have you tried sudo rm - rf / ?
<adrien_oww> ...
<jyeo> radditz: why not you try that and tell me what happens?
<radditz> jyeo: it fixes the camlp4 order
<jyeo> awesome
<adrien_oww> radditz: anything else to add?
<jyeo> adrien_oww: let's be civil and not feed the troll. I don't wanna lose further faith in humanity.
<radditz> jyeo: do you have a specific way to change order? you always have to change the first argumetn with the second?
<radditz> jyeo: I don't know how they are generated, but is there a logical order you need? that is easily identifiable?
_andre has joined #ocaml
<jyeo> apparently, camlp4 reads the cma files from right to left. it works with a particular order but not the other way around
<jyeo> radditz: by the way, I am seriously wondering if u are asking a genuine question
<radditz> well IDK how it works,. but would it be a reasonable solution to make your own camlp4 script that changes the order and calls the true camlp4 command? by changing the PATH maybe ?
<jyeo> radditz: na, that defeats the purpose of using ocamlbuild in the first place. i want ocamlbuild to find my packages without specifying too many things.
<jyeo> i can use a custom makefile to do that but i have to specify the location of my packages, etc
justdit has joined #ocaml
<jyeo> that's not very portable :-/
<radditz> excuse my ignorance, what exactly changes the order of the files? your build still succeeds?
<radditz> I mean what change does the order of the camlp4 parameters imply?
<jyeo> it reads the cma files in a different order
<radditz> and that means...?
ivan\ has quit [Quit: ERC Version 5.3 (IRC client for Emacs)]
justdit has quit [Read error: Connection reset by peer]
justdit has joined #ocaml
sepp2k has joined #ocaml
<jyeo> radditz: I get this error when it's read in the wrong order
<jyeo> Camlp4: Uncaught exception: DynLoader.Error ("/Users/mapleleaf/.opam/system/lib/pa_debug_lib/pa_debug_syntax.cma", "error while linking /Users/mapleleaf/.opam/system/lib/pa_debug_lib/pa_debug_syntax.cma.\nReference to undefined global `Pa_deriving_common'")
<jyeo> pa_debug depends on pa_deriving
<radditz> jyeo: isn't there a depencency resolution?
<radditz> I assumed there was a program to fix dependencies ?
<jyeo> i am not sure how to do that :-/
<radditz> I think for most of them ocamlbuild does it automatically, but there is a special ocamlbuild "makefile" that declares them, no?
<radditz> strange the documentation says that dependencies are automatically resolved
<radditz> adrien_oww: is it true?
<jyeo> i am hoping someone who is more experienced with ocamlbuild can answer me. :-/
<radditz> jyeo: I always assumed that you do ocamlbuild mainfile and dependencies are resolved
<jyeo> not really.
<jyeo> radditz: when you deal with camlp4 and ocamlfind packages, things get a lot hairier.
<jyeo> ocamlbuild does not resolve dependencies between ocamlfind packages
<radditz> right
<radditz> well adrien_oww knows the answer, you can bug him and he will eventually answer
<radditz> adrien
<radditz> adrien
<radditz> adrien
<radditz> say his name 3 times to summon him
<radditz> contempt: companion_cube companion_cube
<radditz> you can also name an alternative program that does this in another language for bonus motivation points
<radditz> OMG ocamlbuild doesn't allow me to manually generate dependencies, but ant totally does, I thought ocaml was better than that?
<radditz> and to think ant wasn't even made by researchers
<radditz> I am totally dissapointed guys
<whitequark> I think ocamlfind should be resolving the deps
<radditz> jyeo: maybe you have to add them to your ocaml libs directory for ocamlbuild to detect them?
iZsh has quit [Excess Flood]
csakatoku has quit [Remote host closed the connection]
dsheets has joined #ocaml
iZsh has joined #ocaml
iZsh has quit [Excess Flood]
radditz has quit [Ping timeout: 250 seconds]
w0rm_x has joined #ocaml
breakds has joined #ocaml
ivan\ has joined #ocaml
Kakadu has quit [Ping timeout: 250 seconds]
steshaw has joined #ocaml
bnoordhuis has quit [Ping timeout: 245 seconds]
steshaw has quit [Remote host closed the connection]
steshaw has joined #ocaml
iZsh has joined #ocaml
iZsh has quit [Excess Flood]
Kakadu has joined #ocaml
paolooo has quit [Quit: Page closed]
avsm has quit [Quit: Leaving.]
mlh has quit [Ping timeout: 252 seconds]
jbrown has quit [Remote host closed the connection]
ocp has quit [Ping timeout: 245 seconds]
Drup has joined #ocaml
talzeus_ has quit [Remote host closed the connection]
talzeus_ has joined #ocaml
talzeus_ has quit [Ping timeout: 272 seconds]
bnoordhuis has joined #ocaml
iZsh has joined #ocaml
_5kg has quit [Ping timeout: 272 seconds]
fryguybob has quit [Remote host closed the connection]
justdit has quit [Ping timeout: 252 seconds]
justdit_ has joined #ocaml
radditz has joined #ocaml
<radditz> jyeo: did you findd the solutiomn?
<jyeo> radditz: yep, sort of
<radditz> jyeo: mind sharing it?
<jyeo> radditz: I have a myocamlbuild.ml file that was controlling the arguments to camlp4
<radditz> jyeo: so you manually give the order?
<jyeo> i removed the myocamlbuild.ml file and it worked
<jyeo> the myocamlbuild file was screwing up the order
<jyeo> zzzz
<jyeo> i didn't know that until i tried to compile my file in another directory
<radditz> so ocamlbuild can find dependencies by itself?
bnoordhuis has quit [Ping timeout: 268 seconds]
<radditz> jyeo: so now you have no build.ml at all? what is the use of myocamlbuild.ml anyway?
<jyeo> AFAIK, it's to do some crazy fine tuning of the build automation. you can customize more things.
<adrien_oww> jyeo: ah; where is that myocamlbuild.ml file from?
mchqwerty has joined #ocaml
<jyeo> adrien_oww: oasis. I was compiling a library in the same directory. I use oasis to make it 'ocamlfindable'
<adrien_oww> ah
<adrien_oww> I wouldn't have expected issues but I can see this go wrong
breakds has quit [Remote host closed the connection]
thomasga has joined #ocaml
<jyeo> yes. I took a week to fix this bug.
darkf has quit [Quit: Leaving]
<radditz> jyeo: what do you mean in the same directory? as the source code?
<jyeo> yes
<radditz> jyeo: I don't understand why that didn't work, I assumed it was because of the myocamlbuild file
<jyeo> ocamlbuild reads the myocamlbuild.ml first before doing build automation stuff
<radditz> jyeo: so why can't you remove the file and compile in the same directory?
<jyeo> radditz: yep, that's what I did.
<radditz> jyeo: oh ok
<jyeo> it's fixed now
<jyeo> thanks radditz
<radditz> jyeo: I don't think I helped you, no need to thank me
<jyeo> come on, i'm just being polite :P
BitPuffin has joined #ocaml
talzeus_ has joined #ocaml
<radditz> jyeo: thank you
Enjolras has joined #ocaml
avsm has joined #ocaml
jbrown has joined #ocaml
jbrown has quit [Ping timeout: 272 seconds]
talzeus__ has joined #ocaml
jbrown has joined #ocaml
avsm has quit [Quit: Leaving.]
talzeus_ has quit [Ping timeout: 260 seconds]
djcoin has joined #ocaml
bnoordhuis has joined #ocaml
avsm has joined #ocaml
justdit_ has quit [Ping timeout: 246 seconds]
jbrown has quit [Read error: Operation timed out]
saml has quit [Quit: Leaving]
mcclurmc has joined #ocaml
ollehar has joined #ocaml
saml has joined #ocaml
jbrown has joined #ocaml
amirmc has joined #ocaml
paolooo has joined #ocaml
shinnya has joined #ocaml
ocp has joined #ocaml
cesar_ has joined #ocaml
cesar_ is now known as Guest49414
ocp has quit [Read error: Operation timed out]
jbrown has quit [Ping timeout: 245 seconds]
justdit has joined #ocaml
Guest49414 has quit [Remote host closed the connection]
boogie has joined #ocaml
Kakadu_ has joined #ocaml
avsm has quit [Quit: Leaving.]
w0rm_x has quit [Ping timeout: 245 seconds]
<companion_cube> radditz: ?
<radditz> companion_cube: ?
<companion_cube> you hl me :p
<Kakadu> ?
ocp has joined #ocaml
<companion_cube> ocp: hey, your team ignores my opam pull request :p
demonimin has quit [Ping timeout: 240 seconds]
radditz has left #ocaml []
radditz has joined #ocaml
<radditz> companion_cube: accident
<radditz> I left by accident
<radditz> companion_cube: contempt cthuluh
justdit has quit [Quit: Lost terminal]
mchqwerty has quit [Ping timeout: 245 seconds]
ollehar has quit [Quit: ollehar]
Kakadu_ has quit [Ping timeout: 240 seconds]
yacks has joined #ocaml
demonimin has joined #ocaml
radditz has left #ocaml []
rand000 has joined #ocaml
<AltGr> companion_cube, hmm, the opam-repository maintainers are not exactly the OCamlPro team, although there is a non-void intersection.
<AltGr> 1.1 PRs should now be safe though
<companion_cube> hmm, right, there are people at cambridge too?
<companion_cube> AltGr: really? hope mine will pass then ;)
<AltGr> 1.0 clients are now stuck on the opam-1.0 branch :)
paolooo has quit [Ping timeout: 250 seconds]
cesar_ has joined #ocaml
cesar_ is now known as Guest48696
Yoric has quit [Ping timeout: 268 seconds]
dsheets has quit [Quit: Leaving]
Guest48696 has quit [Remote host closed the connection]
nikki93 has joined #ocaml
<thomasga> companion_cube: I've just pulled your PR
nikki93 has quit [Ping timeout: 240 seconds]
<companion_cube> thank you
yezariaely has quit [Quit: Leaving.]
Xenasis has joined #ocaml
<jpdeplaix> thomasga: now that we are forced to use the new url as the default repository, is it updated as quickly as the git is ?
<jpdeplaix> I changed the url of the default repository to take the git
<AltGr> jpdeplaix, as before, it's updated every hour
amirmc has quit [Quit: Leaving.]
<jpdeplaix> :(
avsm has joined #ocaml
<companion_cube> would be nice (and motivating) to have some opam-bot on this chan
<companion_cube> to announce new releases
<AltGr> wow, that could quickly get noisy ;)
<companion_cube> if it's every hour, it's ok, right?
<companion_cube> it's not as if it would interrupt many discussions
<jpdeplaix> there is already such a bot on #ocamlpro
<jpdeplaix> (kind of)
amirmc has joined #ocaml
<companion_cube> I don't know whether people here would be disturbed by the bot here
<companion_cube> anyway, have to leave
<nicoo> See you, C³
<adrien_oww> ?
<adrien_oww> nah, avoid news every hour; it gets annoying quickly
<adrien_oww> CIA bots are nice as long as they don't write infrequently
<gour> i just read comments for http://www.reddit.com/r/programming/comments/kuhn3/ocaml_for_the_masses/ and several people complained about lack of unicode support in the language itself. it something going to happen in regard in the future?
mika1 has quit [Quit: Leaving.]
q66_ has joined #ocaml
q66 has quit [Disconnected by services]
q66_ is now known as q66
cesar_ has joined #ocaml
cesar_ is now known as Guest55735
ambul has joined #ocaml
Yoric has joined #ocaml
amirmc1 has joined #ocaml
amirmc has quit [Read error: Connection reset by peer]
Guest55735 has quit [Remote host closed the connection]
tane has joined #ocaml
nisstyre has joined #ocaml
moro_home has quit [Read error: Connection reset by peer]
dsheets has joined #ocaml
ttamttam has quit [Quit: ttamttam]
amirmc1 has quit [Quit: Leaving.]
Kakadu has quit [Quit: Page closed]
boogie has quit [Remote host closed the connection]
Neros has joined #ocaml
moro_home has joined #ocaml
q66 has quit [Ping timeout: 260 seconds]
amirmc has joined #ocaml
AltGr has left #ocaml []
avsm has quit [Quit: Leaving.]
djcoin has quit [Quit: WeeChat 0.4.1]
boogie has joined #ocaml
sepp2k has quit [Quit: Konversation terminated!]
<BitPuffin> Does ocaml provide a way to do manual memory management?
<Drup> No.
<BitPuffin> :(
<Drup> why ?
<BitPuffin> I think every language should
<Drup> > why ?
<BitPuffin> Because there are times where it might be needed
<BitPuffin> GC doesn't always work
<pippijn> when?
<pippijn> (you are right)
<pippijn> but when?
<BitPuffin> so if there is a module that can win from doing manual memory management you should have the option
avsm has joined #ocaml
<pippijn> you can have object pools
<BitPuffin> pippijn: depends on the type of GC I guess?
<BitPuffin> Different GCs have different flaws
<pippijn> ok, so when does the ocaml gc not work for you?
shinnya has quit [Ping timeout: 240 seconds]
<BitPuffin> Well I haven't used ocaml enough to encounter such a situation
<pippijn> then do so
<BitPuffin> But i'm sure I will when I do my game project
<pippijn> before claiming it doesn't meet your needs
<BitPuffin> pippijn: I never said it doesn't
<pippijn> you said ocaml should have manual memory management
<mrvn> bah
<BitPuffin> I said I think every language should have manual memory management
<BitPuffin> not as the proferred way of doing things obviously
<pippijn> ocaml doesn't provide a way
<pippijn> but there are ways
<BitPuffin> (kind of like impurity isn't preferred)
<Drup> the issue is that if you allow it, people *will* screw with it
<Drup> in bad ways.
<pippijn> impurity is embraced
<BitPuffin> pippijn: Yeah I was speculating that if GC becomes a problem I could write a particular module "back end" in C or something
<pippijn> possibly
<BitPuffin> Drup: I don't think I agree
<BitPuffin> Drup: and that's on them anyways
<pippijn> or use object pools
<mrvn> BitPuffin: you can but it is complex.
<pippijn> and/or magic
<mrvn> you would have to register your own objects as gc roots
<pippijn> if the objects contain ocaml pointers, yes
<mrvn> If not then you simply malloc() them and you are done
q66 has joined #ocaml
<BitPuffin> pippijn: what are object pools? :)
<pippijn> in the simplest case: a free list
<jpdeplaix> BitPuffin: maybe the module Gc can help you http://caml.inria.fr/pub/docs/manual-ocaml/libref/Gc.html
<pippijn> a list of objects that you no longer use, and when you request an object and there are free objects, you return one and pull it off the list instead of allocating a new one
<pippijn> useful mostly for large objects
<Drup> BitPuffin: no, I mean that it it's allow "normally", then the gc will have to handle this case and may be penalized by doing so. To allow something that are not very useful (even if you don't agree, you just don't know what you are talking about), you penalize everyone else
<Drup> and this is a bad compromise.
<pippijn> you don't need to use a list, you can use an array to store the references
stevej has quit [Read error: Connection reset by peer]
skchrko has quit [Ping timeout: 260 seconds]
<pippijn> when you're done with an object, you stuff it into the list
<mrvn> which makes the GC slower for no reason
<BitPuffin> pippijn: cool technique
<ggole> Everything has to be mutable for that to work
<pippijn> ggole: correct
<pippijn> mrvn: possibly
<ggole> And it isn't necessarily faster, since you get a write barrier hit
<pippijn> ggole: correct
<pippijn> but it *can* be faster
<ggole> But it... right
<pippijn> and it can be quite a lot faster, too
<ggole> It might be profitable or even necessary in some situations
<pippijn> especially when your object contains mostly ints
<pippijn> because then you don't have the write barrier
stevej has joined #ocaml
<ggole> You can rewrite things as arrays of immediate values, too
<ggole> To get rid of pointers and allocations
<pippijn> right
<ggole> Although this is writing Fortran in OCaml, and is a pretty desperate move
<pippijn> but that can easily become unmaintainable
<pippijn> I haven't done that
<ggole> If the patterns are right you can hide the junk underneath modules
<Drup> pippijn: did you actually need this technique in reality ?
<pippijn> Drup: yes
<pippijn> and it helped
<Drup> your parser ?
<ggole> Ie, module Foo type t = int ... end
<pippijn> yes
<BitPuffin> Drup: Well but like I said it shouldn't be a preferred solution, just _a_ solution. And the GC shouldn't even get to know about it
<Drup> yeah, quite a special case
bnoordhuis has quit [Ping timeout: 245 seconds]
<BitPuffin> Drup: I is best avoided, but should not be forbidden
<BitPuffin> it
<BitPuffin> *
<pippijn> it isn't forbidden
<pippijn> you can implement your own memory model on int arrays
<BitPuffin> I guess
<BitPuffin> Should work
<pippijn> but really, don't do that unless you *really* have to
<BitPuffin> I guess it isn't too hard to just bind alloc etc.
<BitPuffin> pippijn: exactly
<BitPuffin> I'm not asking to do it really
<BitPuffin> I just want to know that I have the option
<pippijn> sure, you can use BigArray
<pippijn> for blocks of C memory
<BitPuffin> and wanted to check how much ocaml would get in the way if I ever needed to do that
<ggole> Hmm, could int64 arrays/records use the float array representation?
<mrvn> then compare fails and I guess get/set breaks
<pippijn> mrvn: how?
<ggole> Oh, compare. Right.
<pippijn> why does compare fail?
<mrvn> in polymorphic functions
<ggole> I don't think access would be a problem though
<ggole> Because compare looks at the tags and thinks "oh, an array of floats".
<Drup> BitPuffin: I really doubt you will need it. Tweaking the GC will probable prove far more fruitful.
<BitPuffin> Drup: Yep
<mrvn> ggole: polymorphic get/set would detect the double array tag and then store the int64 as float.
<Drup> probably*
<pippijn> ah
<BitPuffin> Drup: I will always prefer trying to work with the GC
<pippijn> ok
<ggole> mrvn: they are the same size, so it should be fine
<ggole> (Unless I'm missing something)
<pippijn> I think that will work
<mrvn> hmm, maybe
<ggole> They only place where you need type specific instructions (movsd, etc) are the places where you already know the type
<pippijn> and float comparison is also done with ==, isn't it?
<ggole> But, compare.
mort___ has quit [Ping timeout: 272 seconds]
<pippijn> ah, with <
<mrvn> but read the recent thread about a different GC header format on the list for a better solution
<pippijn> yeah, you might get NaN or Inf accidentally
skchrko has joined #ocaml
<pippijn> yes, giving it an Int64-array-tag would be better
jbrown has joined #ocaml
nikki93 has joined #ocaml
wolfnn has quit [Read error: Operation timed out]
avsm has quit [Quit: Leaving.]
amirmc has quit [Quit: Leaving.]
stevej has quit [Read error: Connection reset by peer]
jakub has joined #ocaml
stevej has joined #ocaml
ollehar has joined #ocaml
manizzle has joined #ocaml
<jakub> Hi! I want to write a function which splits list of numbers into odd and even ones but without using tail recursion. Here is what i have already done: http://pastebin.com/d1gKg2iT but i think it can be done better. The main problem is: how to easly get to the lists contained in tuple returned from function. What is the easiest way to do this?
<mrvn> better would be tail recursion
<ggole> I take it this is homework: otherwise, List.partition is right there
<Drup> jakub: why "without using tail recursion" ? :p
<mrvn> jakub: use pattern matching
<mrvn> jakub: let (even, odd) = split t in
<jakub> ggole: you;re right, my task is to write two version, the one using tail recursion and the one without tail recursion and then to compare this two versions
<Drup> oh
<Drup> then, your version is fine.
<Drup> you can simplify a bit the part on next, by removing k_1 and k_2 and using the pattern matching directly
<Drup> this syntax : let (x,y) = z in ... is allowed.
<mrvn> jakub: let rec split list = match list with ---> let rec split = function
<ggole> k_1 and k_2 are also already available as fst and snd
amirmc has joined #ocaml
<mrvn> jakub: are you allowed to use List.fold_*?
<jakub> mrvn: i guess no
<mrvn> figures
<mrvn> jakub: if you add a linebreak before "then" you get better indentation too
ocp has quit [Ping timeout: 245 seconds]
<jakub> mrvn: really? then is ussualy put on it's own line? just one word? :)
<jakub> ok, i see
<Drup> (I disagree with him on the good looking aspect of his indentation, fwiw)
<Simn> (me too)
<ggole> http://ocaml.nopaste.dk/p63409 That's how I would format it
<ggole> Of course all of this is a matter of taste.
<mrvn> totaly.
manizzle has quit [Ping timeout: 245 seconds]
<Drup> what part didn't you understood in "without using tail recursion" ?
<mrvn> Drup: I'm already at the second part: do it with tail recursion and compare
<Drup> it's not an exercise for you, it's one for him
<mrvn> he will get there
<Drup> or he will click on your version and be spoiled.
<Drup> seriously u_u'
<mrvn> and I doubt he will use optional arguments
<jakub> actually i have already done it, for me it was the easier part :)
<jakub> mrvn: but wow, can you please tell me what does it mean: "?(even = []) ?(odd = [])"?
<mrvn> jakub: It's an optional argument with default value.
<mrvn> jakub: if you don't specify it the compiler adds []
<mrvn> # split [1;2;3;4;5;6];;
<mrvn> - : int list * int list = ([2; 4; 6], [1; 3; 5])
<jakub> i see, nice thing i alwasy had to wirte inner functions which took acumulators, now i won't have to
<Drup> actually, you do
<Drup> if you don't want the optionnal argument to be avaible
<mrvn> jakub: well, an inner function is faster
<ggole> Usually you would write a HoF (or use one already written)...
<mrvn> ?(even = []) internally adds: let even = match even with None -> [] | Some x -> x in
<mrvn> jakub: have you tested how long a list you can split without tail recursion?
<jakub> not yet
Yoric has quit [Ping timeout: 260 seconds]
<jakub> have to write some element-duplicating function, don't want to break my keyboard :)
<mrvn> let longlist n = let rec loop acc = function 0 -> List.rev acc | n -> loop (n::acc) (n-1) in loop [] n
<mrvn> -List.rev
amirmc has quit [Quit: Leaving.]
<jakub> it's better than i thought, still can do:split2 (longlist 100000);; but the next "0" added to n causes stack overflow :)
<mrvn> you don't have many local variable on the stack frame.
<ggole> Is that in the toplevel? The number might be larger for ocamlopt-compiled code.
<mrvn> jakub: you can time the two functions too, see which one is faster
<jakub> yes, it's toplevel, mrvn does it require compilation or can this be done with code?
<mrvn> ggole: I find that already large. Python only does like 5000 and doesn't even understand tail recursion at all.
<mrvn> jakub: timeing? can be done in both
<ggole> Yeah, a lot of interpretery languages have low limits
<mrvn> #require "unix";;
<mrvn> # let time fn = let start = Unix.time () in let res = fn () in Printf.printf "%f seconds\n" (Unix.time () -. start); res;;
<ggole> On a 64-bit machine the limit could arguably be huge
<mrvn> val time : (unit -> 'a) -> 'a = <fun>
<ggole> Plenty of space, after all
<mrvn> ggole: stack is usualy rather limited
<jakub> mrvn: ok, i founed Sys.time() works on windows
<ggole> That could probably be changed (OCaml doesn't need to worry about sparking up many threads).
bnoordhuis has joined #ocaml
<mrvn> Sys.time is even better, subsecond accuracy
<mrvn> Unix.time is time in seconds.
<mrvn> ggole: you can implement ocaml stackless.
bnoordhuis has quit [Ping timeout: 240 seconds]
<ggole> gettimeofday is probably what you'd use from Unix
<ggole> mrvn: right, there was an SML implementation that worked that way iirc
<ggole> SML/NJ?
amirmc has joined #ocaml
amirmc has quit [Client Quit]
Drup has quit [Ping timeout: 252 seconds]
<pippijn> ggole: SML/NJ uses heap-allocated continuation frames
<pippijn> or, I'm not sure whether the current implementation does
<pippijn> but there was something like that
manizzle has joined #ocaml
<ggole> Yep, I remember Appel going on about how stacks weren't any better
<ggole> Which seems suspicious to me
<Xenasis> If I had a list of size Y, which I'd want to split into a list of lists (where the internal lists are of size X), how would I do that?
happy4crazy has joined #ocaml
<def-lkb> I would do that with to functions: one "split: int -> 'a list -> 'a list * 'a list" where in "head, tail = split n l", split the list l into an head of size at most n and a tail with the remaining items
<def-lkb> two functions*
happy4crazy has quit [Remote host closed the connection]
<def-lkb> The second one would just repeat "split" until the tail is empty
<Xenasis> hmmm
<mrvn> .oO(get List.nth, get List.tl, Obj.magic the first into a record with mutable second field and set it to [], repeat with second)
<def-lkb> :D
<mrvn> But that would be destructive to the list
<Xenasis> Obj.magic is a real thing
<Xenasis> ...
<Xenasis> wow
wolfnn has joined #ocaml
<def-lkb> Don't use Obj.magic :P, http://pastebin.com/QMEyfjkt
<ggole> Why two functions? Easy enough with one (the usual inner recursive thing).
manizzle has quit [Remote host closed the connection]
<Xenasis> Ah, thanks, def-lkb! I'll give this a read
demiurgo has joined #ocaml
manizzle has joined #ocaml
<Xenasis> Hah, I didn't know you could do match x, y with
<Xenasis> I thought you were restricted to one
demiurgo has left #ocaml []
<pippijn> allocation in moving GCs is the same as a stack allocation
<pippijn> but deallocation is more expensive
<ggole> Technically you are: the x, y is a tuple
<ggole> It's similar but not the same
<Xenasis> Oh, I thought that required brackets, but I see what you mean
<def-lkb> ggole: A function to extract n items is useful on its own, http://hackage.haskell.org/package/base-4.6.0.1/docs/Prelude.html#v:splitAt
<ggole> Soley because the gc might copy around the objects, so you need to keep a pointer to each one (over a call which might GC: you can make accesses directly until then, I guess).
<ggole> def-lkb: ah, that's a good argument
<def-lkb> Xenasis: my implementation goes wrong if the integer argument is negative
<def-lkb> or null :)
<Xenasis> Right
<Xenasis> Honestly, this isn't even the function I need, but I sort of didn't want to ask for some implementation straight up :P
<Xenasis> So I asked for something similar so I can find out more about these sorts of things!
<Xenasis> Now hopefully I can figure it out myself
<def-lkb> You're welcome.
<Xenasis> I did say thanks :$
<Xenasis> but yeah, thanks again
<def-lkb> :)
Drup has joined #ocaml
Yoric has joined #ocaml
MoHaX has joined #ocaml
<nicoo> Why do people keep wanting to use unsafe coercion ?
<def-lkb> Sometimes the typer need external hints to do ist job :'
<def-lkb> its*
<Drup> an unsafe coercion is not an hint, it's "shut up, I know better than you"
<pippijn> some programs can't be typed in ocaml
mort___ has joined #ocaml
q66 has quit [Quit: Leaving]
q66 has joined #ocaml
<Drup> I didn't say it can't be true :)
MoHaX has quit [Quit: Leaving]
amirmc has joined #ocaml
<Drup> and mrvn, I really hope you are not a teacher irl, because even if you are probably full of good will, you are a terrible at explaining stuff.
ggole has quit []
mort___ has quit [Quit: Leaving.]
<rks`> Drup: and you are a terrible at englishing stuff
<rks`> ;)
<jpdeplaix> :DDD
<companion_cube> gentlemen! no fighting in the war room!
_andre has quit [Quit: leaving]
amirmc has quit [Quit: Leaving.]
* nicoo hugs companion_cube
<nicoo> pippijn: Yes. And I believe that often, those are programs that we are better off not writing
<pippijn> nicoo: like parsers?
<pippijn> nicoo: and foreign function interfaces?
mort___ has joined #ocaml
<nicoo> extern isn't really magic (but you can easily build magic with it). And yes, Obj.nagic has its uses. But what I meant is that there seem to be some kind of “unhealthy fascination” around Obj.magic.
<nicoo> I mean, gaining local mutability to make a function tail-recursive and more efficient isn't the kind of micro-optimization we should use all over the place.
<companion_cube> I've seen some reasonable uses of it
<companion_cube> btw, it would be nice to have algebraic types with mutable fields
Yoric has quit [Ping timeout: 259 seconds]
w0rm_x has joined #ocaml
<pippijn> Drup: were you the guy who thinks jabber is great?
<Drup> quite possibly
<Drup> not necessarily great, but far better than IRC.
<pippijn> I switched from irc to xmpp mostly for one reason
<pippijn> when I'm talking to someone on irc, and their connection times out, my last N messages (where N is unknown) are lost
<Drup> don't worry, it's far worst when you are on the other side of the bad connection.
<companion_cube> oh, well, irc still works
<pippijn> and I thought xmpp has this
<pippijn> guaranteed message delivery
<pippijn> in fact, though that might be an implementation bug, this is not the case
<Drup> you can't "garantee" in a sense you are not sure that the other guy will ever reconnect.
<pippijn> fine
<pippijn> I'm not up for splitting hairs right now
<pippijn> either way
nikki93 has quit [Remote host closed the connection]
<Drup> but the delay for a timeout to be noticed is very short, compared to irc, and (if the client and the server implement it) you have offline messages
<companion_cube> lazy (split hairs)
<pippijn> what happens is: messages that are sent when the other person is currently timeouting are lost
<pippijn> with prosody xmpp server
mort___ has quit [Quit: Leaving.]
<Drup> and inside a channel, you have the X last messages replayed on connection to the chan.
<pippijn> I'm using it primarily for one on one communication
<Drup> companion_cube: on the "irc still works" stuff, yes, Java and C++ too. :D
<companion_cube> nah
<companion_cube> anyway, it's a network effect (!), it needs everyone to change for the change to work
Yoric has joined #ocaml
ocp has joined #ocaml
zamn has joined #ocaml
Yoric has quit [Ping timeout: 245 seconds]
<zamn> hi, can anyone helpme with this code? for some reason I keep getting "got 'a list list but expected int list". It's my contains() call inside of eval_move(). http://www.zamn.net/puzzle.txt
<companion_cube> for some reason I can't load the page
<companion_cube> but you most likely have some extra "[ ]"
<zamn> still can't?
<zamn> i'd pasetbin but im on a tablet right now so i dont have a mouse -_-
<zamn> tablets make life hard.
<zamn> ok companion_cube im gonna grab a computer
<Xenasis> No need
<Xenasis> I'll od it for you
<zamn> nah its fine Xenasis lol
<zamn> if you do make it private pls
<zamn> its a schoolo project
<zamn> brb
zamn has quit [Quit: leaving]
<Xenasis> unlisted
<Xenasis> yeah
Xenasis has left #ocaml []
Anarchos has joined #ocaml
Yoric has joined #ocaml
jakub has quit [Quit: Page closed]
zamn has joined #ocaml
<zamn> okay, i'm back companion_cube x_x
<zamn> did you get a chance to look at the code?
<zamn> or do you need me to pastebin
<companion_cube> quickly
<zamn> quickly?
<companion_cube> but I didn't see anything obvious :(
<companion_cube> btw, you shouldn't use tuples everywhere for passing arguments to functions
<zamn> why not
<companion_cube> contains already exist in the stdlib: List.mem
<zamn> i'm not allowed to use that
<zamn> sooooo i made one myself
<zamn> is it wrong?
<companion_cube> no problem, it's just useful to know it exists
<zamn> ah ok thanks
<companion_cube> why can't you use the standard lib ? :(
<zamn> we can
<zamn> only things in the pervasives module
<zamn> or something like that
<companion_cube> oh.
<companion_cube> ok, makes sense for learning, but remember stuff exists for later ;)
<companion_cube> so, b is a list of lists?
<Drup> zamn: can you paste everything ? it lacks some parts ?
<zamn> yes
<zamn> okay Drup
<zamn> there you go Drup and companion_cube
<zamn> so i'm getting an error on in solve_board on (h::t) -> ..
<zamn> it says "this expression has type 'a list but an expression was expected of type 'a. The type variable 'a occurs inside 'a list."
<mrvn> line?
<zamn> 335
<zamn> is_sorted is on 155
<companion_cube> oh, yes
<companion_cube> if .... then [b] .... else [[b]]
bnoordhuis has joined #ocaml
<mrvn> since when is [] not sorted?
<zamn> i'm not testing [[
<companion_cube> zamn: it's a type error
<zamn> i'm passing in [3;2;1;0] into solve_board
<zamn> yea companion_cube i'm not sure why x_x
<companion_cube> zamn: because if b has type 'a, then [b] has type 'a list, and [[b]] has type 'a list list
<mrvn> zamn: function application does not use ()
<companion_cube> which is not the same as 'a list
<mrvn> else print_boards make_moves(b)
<mrvn> That calls print_boards with 2 arguments, make_moves and b
nikki93 has joined #ocaml
nikki93 has quit [Remote host closed the connection]
nikki93 has joined #ocaml
<zamn> yeah mrvn ignore that
<zamn> that was me failing at debugging
<mrvn> zamn: I think quite a few of your [] cases should be "assert false"
<zamn> okay i'll update it a bit
<mrvn> does fixing the [[b]] solve your problem?
<zamn> http://pastebin.com/r0AiX3En <- updated code
<zamn> what am i fixing about [[b]] ?
<mrvn> [] -> [b] is wrong
<zamn> i removed that
<zamn> completely
<zamn> 328
darkf has joined #ocaml
<zamn> and still same error
<mrvn> you are missing an eval_moves
<zamn> ah yeah forgot to uncomment that part form my code
BitPuffin has quit [Read error: Connection reset by peer]
<mrvn> it's also wrong :)
<zamn> whats wrong about it?
<zamn> x_x
<mrvn> if is_sorted(h) then h::endlist
<zamn> i hate this type inference stuff
<mrvn> That is an int list list. But you need an int list list list
<mrvn> zamn: annotate the types
<zamn> annotate?
<mrvn> let rec moves : (int list * int list list * int) -> int list list list = function (b, endlist, n) -> ...
<zamn> ah okay
<mrvn> you can put types anywhere in the code where you are unsure
<mrvn> if is_sorted (b : int list)# let foo x = (x : int) + 1;;
<mrvn> val foo : int -> int = <fun>
<zamn> uh
<zamn> so
<mrvn> Usualy when you get strange type errors putting a few types here and there will give you a better picture.
<zamn> so i'm not putting the type inference in the function itself?
<zamn> just where i call it
<mrvn> wherever you suspect the type might be unclear or wrong
<zamn> okay
<zamn> so in line 330
<mrvn> you can also do "ocamlc -i foo.ml" to get the files signatures (with the bad functions commented out).
<mrvn> Nice for checking that what you have so far has the right types.
<zamn> i can make that: eval_moves((make_moves b : int list list), ([b] : int list list), (n : int))
<mrvn> yes
<mrvn> bit overkill
<mrvn> zamn: I think the problem though is that you are thinking wrong. Your eval_moves can't work that way.
tane has quit [Quit: Verlassend]
<zamn> can't work what way?
<zamn> i'm trying to pass to eval_moves a int list list, int list list, and an int
<zamn> thats what i *think* i'm passing but ocaml says otherwise
<zamn> and god forbid i could debug this
<zamn> print statements? NOPE
Yoric has quit [Remote host closed the connection]
<mrvn> comment out your solve_board and run ocamlc -i foo.ml. Then paste the type of eval_moves
<zamn> it says syntax error on #use "testUtils.ml";;
<zamn> Error: This expression has type int list list but an expression was expected of type int list
<zamn> thats what I get
<zamn> in eval_moves
<mrvn> hmm, #use is only for the toplevel. then you have to paste it there.
<zamn> i commented it out
steshaw has quit [Ping timeout: 240 seconds]
<mrvn> Is that commented out code you pasted last your current eval_moves?
<pippijn> Drup: skype is the only messenger I know that does message delivery right
<zamn> yeah let me update the paste
<Drup> did you actually get issues with xmpp ? Even on crappy connections, I didn't had any.
<pippijn> Drup: actually skype could improve on one point: there are no offline messages
<zamn> and mrvn ^^
<zamn> so line 324 is where i'm getting my error
<pippijn> the server doesn't keep messages, but the client does
<zamn> (the one i pasted above)
<pippijn> so messages can only be exchanged when both are online
<pippijn> which is necessary due to end to end encryption
<pippijn> which is a good thing™
<pippijn> but I think skype doesn't have end to end encryption (anymore)
<mrvn> zamn: you want type (int list list * int list list * int) -> ...?
<pippijn> Drup: yes, namely when the connection times out
<pippijn> Drup: it might be a server bug, though
<pippijn> maybe xmpp is not to blame
<zamn> mrvn: i want b to be int list list, endlist to be int list list
<zamn> i'm iterating through b which is supposed to iterate through each inner list
<mrvn> zamn: you are aiming to make this tail recursive?
<zamn> mrvn: i'm just trying to solve this x_x
<zamn> mrvn: as long as the head isnt in the endlist then i want to keep going on that head
<mrvn> zamn: b is your list of possible next boards, endlist are the moves you did so far (list of boards).
<zamn> yes
<Drup> pippijn: be in a chanel completly solve the whole issue, but I'm not sure about 1-1 conversation, I don't use it that much
<mrvn> zamn: so you recursively test all boards and when you have tested them all you return the list of moves you did so far?
<zamn> yes!
<zamn> is that wha tmy code says?
<zamn> lol
<zamn> thats what i tried writing.
<pippijn> Drup: in a channel, I can't have end to end encryption
<mrvn> that is line 323 and wrong
<Drup> indeed
<zamn> mrvn: i'm not sure what to do for an empty list
<mrvn> zamn: you start with endlist = [start_board], right?
<pippijn> I want that, so I need a 1-1 conversation
<zamn> yes
<mrvn> zamn: so your eval_moves would do a lot of recursive things and then return [start_board]
<zamn> well, the end goal is to never run into the case where b is empty
<mrvn> That isn't a solution for sure
<zamn> i just put that to make it shut up about wranings
Yoric has joined #ocaml
<mrvn> zamn: use assert false
<zamn> okay but i still have that error after putting that
<pippijn> in skype, the messages are kept by the sending client and when establishing a communication channel, the clients somehow exchange information on which messages have been received and which have not
<mrvn> ok, other pattern
<mrvn> h is the next possible board and t the remaining possibilities.
<pippijn> so if you have two receiving clients on different computers, you can still get all the messages the sending client knows about, even when they are not logged in at the same time
<zamn> mrvn: yes t are the remaining possiblilities
<pippijn> xmpp also doesn't seem to broadcast private messages to all presences
<zamn> ah i see, i never actually iterate through t
<mrvn> zamn: is_sorted h only makes sense if n == 0
<zamn> no because there can be solutions <= n
<zamn> i want to stop when i've gone >= n times
<mrvn> that would be stupid, then you called it with a too big n. I'm assuming at the end you will try to solve it for n=1,2,3,4,5, till you get a solution.
<mrvn> and the exercise asks for "Given board b, return all solutions of length n"
<zamn> yeah
<nicoo> pippijn: Actually, offline messages & encryption aren't incompatibles.
<zamn> so thats why i return [[[blah]]]
<mrvn> so first thing I would check "if n == 0"
<mrvn> if n == 0 then you have to check if any of the boards in b are sorted.
<mrvn> if so then you have a solution.
<mrvn> if n != 0 you do the recursive thing with contains.
<zamn> uh
<mrvn> does that make sense?
<zamn> yeah that mostly makes sense
<zamn> so i'm gonna start with n > 0
<zamn> and every recursive call i decrement n
<zamn> right
<mrvn> yep
<zamn> okay
<zamn> so where should i put that logic
<zamn> heh
<zamn> should i be modifying my solve_board?
MoHaX has joined #ocaml
<mrvn> No, that comes last. solve_board will be just a wrapper to your eval_moves
<zamn> yeah thats how ive been using it
<zamn> okay
<zamn> so i do need a match in eval_moves though right?
<mrvn> first test n
<zamn> okay
<mrvn> e.g. if n == 0 then check_solution(b, endlist) else check_moves(b, endlist, n)
<zamn> wait so eval_moves is also going to be a wrapper?
<mrvn> you can inline the functions. I like splitting big jobs into little pices.
<zamn> okay
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
<mrvn> val check_solution : (int list list * int list list) -> int list list list
<zamn> why is there a check solution
<zamn> i'm just checking if the last list is sorted
<zamn> if it is then i know all the preceding lists in endlist is correct
<mrvn> b is a list of boards. you need to check if one of them is sorted.
<zamn> oh. yeah.
<mrvn> so you recurse through the b's, if one of them is sorted you return the solution, otherwise an empty list
MoHaX has quit [Ping timeout: 245 seconds]
<zamn> something like that?
<mrvn> s/list/b/
<zamn> er, yeah
<zamn> i'm writing this in pastebin.. makes things easier heh
zpe has quit [Ping timeout: 272 seconds]
<mrvn> line 4 is kind of right but you are returning the wrong type.
Yoric has quit [Read error: Connection reset by peer]
<mrvn> h::endlist is int list list, one solution. You need to return a list of solutions (int list list list)
<mrvn> with one element, the solution you found
<zamn> oh
Derander has joined #ocaml
<zamn> i'm just trying to figure out what each thing is in your context
<zamn> so b is an int list
<mrvn> next line 5: You've checked that h isn't sorted. What about t?
<zamn> endlist is an int list list list
<mrvn> b is the list of possible boards -> int list list
<zamn> yeah..i shold probaby call it again
<zamn> oh okay
<mrvn> endlist the moves -> int list list
<zamn> so basically you're saying go through every iteration up to n adn then check to see if they're actual solutions?
<mrvn> zamn: that is the exercise
<zamn> okay
MoHaX has joined #ocaml
<zamn> so then in my check_solution, b is an int list list
<zamn> so i need another helper
<mrvn> you should call is bs or moves
<mrvn> with s/b/moves/ --> http://paste.debian.net/60606/
<zamn> you said moves was all the possible moves x_x
<mrvn> zamn: all the next moves. Not overall all moves
<zamn> oh okay
<zamn> you're basically doing this from the end to the beginning it seems
<zamn> like the case where we have the list with all the boards that lead up to that solution
Simn has quit [Quit: Leaving]
<mrvn> that is usualy how you learn it. Think factorial. You first define factorial(1), then the n -> n-1 recursion.
<zamn> okay
<mrvn> have you thought about what to do with t in line 5?
<zamn> you mean moves?
<zamn> basically im just confused as to what youre doing
<zamn> we are looping through moves and and checking if eahc move is sorted
<zamn> if it is then we append that move to the endlist
<zamn> but we want _all_ the moves up to that point as well
<mrvn> zamn: the eval_moves will do the recursion and try all possible move combinations. The check_solution checks if the current move sequenze in endlist can be completed to give a sorted board.
<zamn> how can it determine that though?
<mrvn> zamn: if any of the moves is sorted then you have a solution.
<zamn> so we only care about th eheads then
<zamn> cause cause the solutions will always be the last list insid eof the list
<mrvn> zamn: no. any one of the moves might be sorted.
<zamn> yeah but then we need to make a new list from that point onwards
<mrvn> the [move::endlist]?
<zamn> yeah but thats just appending the sorted list to the endlist
<zamn> we need to show th eprocess
<zamn> i.e. the boards up to sorted board
<mrvn> that is in endlist
<zamn> okay
<zamn> that makes sense then
<mrvn> endlist are the boards you used to get here
<zamn> oh
<zamn> and moves is just the possible moves i *could* make form this point onwards
<zamn> and since we only call this when n = 0
<zamn> so this is do or die essentially
<mrvn> exacxtly.
<zamn> so then my else
<zamn> would be just calling check_solution again
<zamn> passing in the tail
<mrvn> yep.
<zamn> so that
<mrvn> which leaves line 3. What do you do when none of the moves are sorted?
<zamn> uh
<zamn> if none of them are sorted then i dont care abou tit
<mrvn> i.e. when you "die"
<zamn> so i return []
<mrvn> zamn: the recursion will try all possible move combinations. billions of them will be dead ends.
<mrvn> yes, [], empty list of solutions
<zamn> okay so now that i have that
<zamn> i need to come up with all the possible moves
<mrvn> make_moves
<zamn> okay
malo has joined #ocaml
Yoric has joined #ocaml
<mrvn> try: let b = [1;2;0;3];; check_solution((make_moves b), [b])
<mrvn> should give [[[1;2;3;0]; [1;2;0;3]]], right?
Yoric has quit [Read error: Connection reset by peer]
<zamn> no
<zamn> :x
<zamn> # let b = [1;2;0;3];; check_solution((make_moves b), [b]);;
<zamn> val b : int list = [1; 2; 0; 3]
Yoric has joined #ocaml
<mrvn> What is a sorted board? [0;1;2;3] or [1;2;3;0]?
<zamn> former
<zamn> oops
<mrvn> or [1;2;3;4]?
<zamn> no a solve board is a board in sorted order
<zamn> not sure why its returning an int list
<mrvn> let b = [0;1;3;2];; let x = check_solution((make_moves b), [b]);;
<mrvn> let m = make_moves b;;
<mrvn> it should swap the 3 and 2 to get a solution
<zamn> yea it gets a solution
<zamn> but still returns an int list
<mrvn> past the code
<zamn> except line3 is [] -> p[
<zamn> [] *
w0rm_x has quit [Ping timeout: 272 seconds]
<mrvn> should return [[[0;1;2;3]; [0;1;3;2]]]
<zamn> i'm using ocaml 4 if that matters
w0rm_x has joined #ocaml
<zamn> when i try doing: [1;2;3]::[4;5;6] on the ocaml interpreter i get an error
<zamn> so could that line possibly be wrong
<mrvn> shouldn't matter. its basic stuff thats been stable for decades.
<mrvn> [1;2;3]::[[4;5;6]]
<mrvn> board::boards
<zamn> ah yeah that works..
<zamn> wtf
<mrvn> what is the type for check_solution?
<zamn> - : 'a list list * 'a list list -> 'a list list list = <fun>
<mrvn> that is correct
<mrvn> can't be returning a list of ints then
<zamn> oh
<zamn> hm
<zamn> # let b = [1; 0; 2; 3];; make_moves(b)
<zamn> that wont even print out make_moves
<mrvn> let m = make_moves(b);;
<zamn> ah okay
<zamn> OK
<zamn> now it works
<zamn> # check_solution(make_moves(b), [b]);;
<zamn> - : int list list list = [[[0; 1; 2; 3]; [1; 0; 2; 3]]]
Yoric has quit [Read error: Connection reset by peer]
<mrvn> Ok, back to eval_moves.
<zamn> thanks for this btw mrvn
<zamn> you are saving me ~_~
<mrvn> I would do "if n <= 0 then check_solution.... else check_moves ...."
<mrvn> n should never be negative but just in case lets catch that there too
<zamn> heh yeah i was trying to think of a case where it'd be negative
<mrvn> can only be negative when you call it with a negative.
Anarchos has quit [Quit: Vision[0.9.7-H-280704]: i've been blurred!]
Yoric has joined #ocaml
<mrvn> lets write the "test_moves" directly in eval_moves, because that needs to call eval_moves recursively.
<zamn> okay
<zamn> i actually tried to do circular recursion in one of my attempts heh
<zamn> i had to use the and keyword
<mrvn> b is the list of next moves you can do, endlist is the list of moves you have already done and n the number of moves you have left to solve the puzzle.
<zamn> right now my test_moves(b, endlist, n) = if n <= 0 then check_solution(make_moves b, endlist) else check_moves(make_moves b, endlist)
<zamn> and my check_moves kind of just takes each seperate move in make_moves b and appends it to endlist
<mrvn> and calls test_moves again?
<zamn> where would it do that
<zamn> after my check_moves(..) ?
<mrvn> in check_moves you have to go through all the moves and for each call test_moves(move, move::endlist, n-1)
<mrvn> with some condition and handling the return values.
<zamn> something like that mrvn ?
<zamn> er, except test_moves will have the right params
<mrvn> aeh, no.
<mrvn> do you want to call the top function test_moves or eval_moves?
<zamn> i like eval_moves
<zamn> cause we're evaluating the moves
<mrvn> then stick with that.
Yoric has quit [Read error: Connection reset by peer]
<zamn> okay. i just got confused by your names heh
<mrvn> You need "let rec ... and ..."
<zamn> ah yeah
thomasga has quit [Quit: Leaving.]
<mrvn> the check_solution is fine on its own, just the last two
<zamn> why doesn't check_solution need a redc?
<zamn> rec * ?
<mrvn> remove the "if n > 0"
<mrvn> zamn: it does, just not "and"
<mrvn> line 11 makes no sense
Yoric has joined #ocaml
<zamn> yeah i realized that
<zamn> so check_moves will be called with the possible moves of b
<mrvn> yes
<zamn> and each variation needs to be appended to endlist
<zamn> but each call will have its own version of endlist
<mrvn> zamn: it will cal eval_moves(h, h::endlist, n-1)
<zamn> oh okay so now i have the circular recursion stuff
<mrvn> line 12 should be "and eval_moves....."
<zamn> oh
<mrvn> that allows the two functions to call each other
<zamn> so like that then
<mrvn> better. check_moves needs the "n"
bnoordhuis has quit [Ping timeout: 240 seconds]
<zamn> derp x| yeah
<zamn> okay
<zamn> so now in check_moves i'm assuming [] -> should be assert false then
Yoric has quit [Read error: Connection reset by peer]
<zamn> cause you should never have [] asb
<mrvn> zamn: now you cann eval_moves for h, but what about all the other moves in t?
<mrvn> s/cann/call/
<zamn> so now i'm writing the wrapper solve_board you're saying?
<mrvn> no, still in check_moves
<zamn> oh
<zamn> yeah oops
<zamn> so i'm asusming i have to do something like: check_moves(eval_moves(h, h::endlist, n-1), endlist, n)
<zamn> on line 11
Yoric has joined #ocaml
<mrvn> no, the eval_moves part for h is right as is.
Yoric has quit [Read error: Connection reset by peer]
<zamn> oh okay
<mrvn> you need to check_moves for t
gour has quit [Ping timeout: 245 seconds]
<zamn> yeah
<zamn> so do i have an in then?
<zamn> or a semi colon
<mrvn> lets do a semicolon for now.
<zamn> so like that
<mrvn> just to get smething that has the right syntax
<zamn> yeah
<mrvn> yep. the eval_moves gives you all the solutions for the case you use move h, the check_moves gives you all the solutions for all the other moves in t. How do you combine the two?
<mrvn> [s1;s2] and [s3;s4;s5;s6;s7;s8]
<zamn> using ::
<zamn> but i need to create another function don't i?
<zamn> in order to hold both of those
<zamn> [a;b]
<zamn> like that
<mrvn> :: adds one elemnt to a list. you have 2 lists
<zamn> so i want to add one list to a list of lists
<mrvn> ever used @?
<zamn> yes i use it tons
<zamn> in this proj
<zamn> list @ 5::[]
<zamn> like that
<zamn> concats two lists
<mrvn> [s1;s2] @ [s3;s4;s5;s6;s7;s8] --> [s1;s2;s3;s4;s5;s6;s7;s8]
<zamn> yeah
<mrvn> That's what you need
<zamn> are you sure? that doesnt seem right
<zamn> its supposed to be a list of lists
<zamn> per solution
<mrvn> it is an int list list list
Yoric has joined #ocaml
<zamn> so you're saying replace ; with @
<mrvn> and add ()
<zamn> around the whole expressoin?
<mrvn> I think, not sure about precedence
<zamn> or around check_moves
<mrvn> around the function calls
<zamn> ah okay
<zamn> so that then?
<mrvn> yeah. Now line 10.
<zamn> yeah. now we care when its empty
<zamn> i'm assuming i just return [] now
<zamn> cause [1;2;3] @ [] is just [1;2;3]
<mrvn> yep
<mrvn> and then one last thing. Back to line 11.
<mrvn> The exercise said that you shouldn't do moves you already had.
Yoric has quit [Read error: Connection reset by peer]
<zamn> yea
<zamn> i made a function that removes duplicates in lists
<zamn> uniq()
<zamn> i can just call uniq around that whole thing?
<mrvn> you had a "contains" before
<zamn> yea
Yoric has joined #ocaml
<zamn> so we want to check if check_moves(t, endlist, n) is already in eval_moves(h, h::endlist, n-1)
<zamn> if it is then we don't append
<zamn> er, concat
<mrvn> no. check if h is in endlist
Yoric has quit [Read error: Connection reset by peer]
<zamn> o
Yoric has joined #ocaml
nikki93 has quit [Remote host closed the connection]
Yoric has quit [Read error: Connection reset by peer]
<mrvn> You want to skip moves that go in a cricle.
<zamn> yeah
<zamn> but i need an else right
<mrvn> yes
<zamn> just not sure what that should be x_x
<mrvn> if endlist contains h you need to skip it
<zamn> so check_moves(t, endlist, n)
<zamn> as my else
Yoric has joined #ocaml
<mrvn> zamn: yes. Or remove the = false ans swap the 2 cases
<zamn> er, didnt fix line 10
<mrvn> "= true" is implicit.
<zamn> wasn't sure
Yoric has quit [Read error: Connection reset by peer]
<zamn> i tried doing !contains(blah) yesterday
<zamn> and i got a weird 'b ref error
<zamn> didnt want to risk heh
<mrvn> hehe, that would be not (contains(blah))
<mrvn> ! is for refrences.
<mrvn> looks good. does it compile?
<zamn> yes
<mrvn> type?
Yoric has joined #ocaml
Yoric has quit [Read error: Connection reset by peer]
<zamn> val check_solution : 'a list list * 'a list list -> 'a list list list = <fun>
<zamn> val check_moves : int list list * int list list * int -> int list list list = <fun>
<zamn> val eval_moves : int list * int list list * int -> int list list list = <fun>
Yoric has joined #ocaml
<mrvn> zamn: any progress with solve_board?
Yoric has quit [Read error: Connection reset by peer]
<zamn> not yet
<zamn> i've been testing eval_moves
<zamn> and im not sure if i'm just doing it wrong
<zamn> or if it doesnt work
Yoric has joined #ocaml
<zamn> eval_moves([1;2;0;3;4;5;6;7;8],[],2);;
<zamn> returns []
<zamn> am i doing it wrong -_-
<mrvn> let b = [1;0;3;2];; let x = eval_moves(b, [b], 1);;
<zamn> oh oops
<zamn> # eval_moves(b, [b], 1);;
<zamn> - : int list list list = []
<zamn> yea even for b = [1; 0; 2; 3] i get []
strobegen has quit [Quit: Leaving.]
<mrvn> let b = [0;1;3;2];; let x = eval_moves(b, [b], 0);; ?
<zamn> # eval_moves(b, [b], 0);;
<zamn> - : int list list list = [[[0; 1; 2; 3]; [1; 0; 2; 3]]]
<zamn> that works for 1;0;2;3
<zamn> let me try yours
<zamn> i think the one you gave me is unsolvable
<zamn> actually heh
BitPuffin has joined #ocaml
<zamn> cause its returning []
Yoric has quit [Read error: Connection reset by peer]
<mrvn> huh? Thats the example from above. just swap 2 and 3
<zamn> yeah
<zamn> thats what im saying with only using the 0 space to swap
<mrvn> let m = make_moves b;;
<zamn> - : int list list = [[1; 0; 3; 2]; [3; 1; 0; 2]]
<mrvn> ok, lets move the 0 twice then: let b = [1;3;2;0];;
<mrvn> let x = eval_moves(b, [b], 1);;
<mrvn> swap 3/0, swap 1/0
Yoric has joined #ocaml
<zamn> yea that works.
<mrvn> what does it give?
<zamn> - : int list list list = [[[0; 1; 2; 3]; [1; 0; 2; 3]; [1; 3; 2; 0]]]
<mrvn> so it works
<zamn> yes
<zamn> thank you :D
<zamn> so i just need to do n-1 in my solve_board
<mrvn> Now write solve() and then save that for save keeping.
<mrvn> Then you can make it better. e.g. fix that "n-1" issue.
<zamn> its already amazing :D
<mrvn> or in eval_moves you have b and endlist. The head of endlist is already b
<zamn> ah yeah
<mrvn> so you might make endlist one smaller.
rand000 has quit [Quit: leaving]
Yoric has quit [Read error: Connection reset by peer]
<mrvn> in eval_moves when n <= 0 you could check if b is sorted instead of doing another make_moves.
wolfnn has quit [Ping timeout: 272 seconds]
Yoric has joined #ocaml
MoHaX has quit [Ping timeout: 272 seconds]
<mrvn> and for extra credits in check_moves user an accumulator and append solutions to it as you find them instead of using @, make it tail recrusive.
<mrvn> make use of the map and fold helpers
<zamn> eh
<zamn> something isnt right x_x
ocp has quit [Ping timeout: 245 seconds]
Yoric has quit [Read error: Connection reset by peer]
<mrvn> how does your solve_board look like?
<zamn> its 1 line
<zamn> eval_moves(b, [b], n-1)
<mrvn> should be right.
<mrvn> let b = [1;3;2;0];; let x = eval_moves(b,2);;
Yoric has joined #ocaml
<mrvn> let b = [1;3;2;0];; let x = solve_board(b, 2);; I mean
Yoric has quit [Read error: Connection reset by peer]
<zamn> yeah that one is failing
<zamn> for b = 3
<zamn> er, n
<zamn> oh because its supposed to be <= n
<zamn> for the solution
<zamn> we dont need n solutions
<zamn> so i have to check_solutions after every check_moves
<mrvn> I read it as == n
<zamn> x:
<mrvn> if you give the wrong n then you get no solutions
<zamn> the tests they supply
<zamn> assume <= n
Yoric has joined #ocaml
chrisdotcode has quit [Quit: No Ping reply in 180 seconds.]
<zamn> is there a trivial solution to this mrvn ?
chrisdotcode has joined #ocaml
<mrvn> I don't see a problem. The example given in the exercise is with == n
<mrvn> solve_board ([1;2;0;3;4;5;6;7;8],2)
Yoric has quit [Read error: Connection reset by peer]
<mrvn> swap 2/0, swap 1/0
<zamn> that returns nothing heh
nikki93 has joined #ocaml
Yoric has joined #ocaml
<mrvn> try 0,1,2,3,4
<zamn> yeah it works for 3..
<mrvn> maybe your offset on n is wrong.
<mrvn> what does it give for 3? The right thing?
<mrvn> [[[0;1;2;3;4;5;6;7;8];[1;0;2;3;4;5;6;7;8];[1;2;0;3;4;5;6;7;8]]]
<zamn> yes
<zamn> oh waits its returning the wrong result
ollehar has quit [Ping timeout: 245 seconds]
<zamn> one of the issues i'm having mrvn
<zamn> is that its printing out the same solution twice
<mrvn> then check the make_moves
chrisdotcode has quit [Ping timeout: 240 seconds]
amirmc has joined #ocaml
<mrvn> you can add print_board calls and other print calls to see the programm flow.
<zamn> thats what im getting
<mrvn> solve_board(c, 1);;
<mrvn> The solution only has 1 move, not 2
<mrvn> The reason that 3 works is that in check_solution you don't check for contain and in check_moves you don't check for solved.
<zamn> okay
<zamn> so in check_solution
<zamn> I should check if endlist contains h
<zamn> before appending?
<zamn> er, prepending
<mrvn> that would catch it
<mrvn> checking for is_sorted in check_moves would be faster though, cuts the search tree off earlier.
<mrvn> FYI: From the hints I think you were supposed to do a width first search. You've done a depth first.
Yoric has quit [Read error: Connection reset by peer]
<zamn> mrvn: right now i'm just trying to do *a solution*
ollehar has joined #ocaml
<mrvn> depth first makes more sense though.
<zamn> yeah
<zamn> it does
<zamn> he doesnt care how we do it
<zamn> so you're saying adding on is_sorted after the contains in check_moves iwll eliminate the duplicates?
<zamn> line 11
Yoric has joined #ocaml
<mrvn> if is_sorted or contains then ...
Yoric has quit [Read error: Connection reset by peer]
<mrvn> or if contains or is_sorted ...
<mrvn> zamn: your wrong solution had an already solved move in the middle.
<zamn> yea
<mrvn> and since you aren't allowed to repeat a board that can never lead to a solution. No need to search recursively in that direction.
bnoordhuis has joined #ocaml
Yoric has joined #ocaml
Yoric has quit [Read error: Connection reset by peer]
<zamn> that fixed it
<zamn> so how would i go about fixing n now x_x
<mrvn> s/check_solution(make_moves b, endlist)
<mrvn> /if is_sorted(b) then [endlist] else []
Yoric has joined #ocaml
Yoric has quit [Read error: Connection reset by peer]
<mrvn> less code and should remove the n-1 issue too I think
bnoordhuis has quit [Ping timeout: 245 seconds]
<zamn> i'm putting that on line
Yoric has joined #ocaml
stevej has quit [Quit: ["Textual IRC Client: www.textualapp.com"]]
<zamn> so on line 16
<zamn> i'm replacing check_solution(..) with if is_sorted(b) then [edlist] else []
<mrvn> that should also solve the wrong answere for 3 moves from above as well without further change. Just not as fast.
<zamn> eh
<zamn> now i get no output
<mrvn> for 1,2,3,4,5?
<zamn> nope
nikki93 has quit [Remote host closed the connection]
<zamn> oh wait
<zamn> x_x
<zamn> oh no. yeah nothing :(
Yoric has quit [Read error: Connection reset by peer]
<zamn> # eval_moves(c, [c], 3);;
<zamn> - : int list list list = []
<zamn> # c;;
<zamn> - : int list = [1; 0; 2; 3; 4; 5; 6; 7; 8]
<mrvn> eval_moves(c, [c], 1);;
<zamn> # eval_moves(c, [c], 1);;
<zamn> - : int list list list = []
nikki93 has joined #ocaml
<mrvn> let b = [0;1;2;3];; let x = eval_moves(b, [b], 0);;
<zamn> # eval_moves(b, [b], 0);;
<zamn> - : int list list list = [[[0; 1; 2; 3]]]
<mrvn> let b = [1;0;2;3];; let x = eval_moves(b, [b], 1);;
<zamn> # eval_moves(b, [b], 1);;
<zamn> - : int list list list = []
Yoric has joined #ocaml
<zamn> http://paste.debian.net/hidden/145167e1/ thats what i have mrvn
<mrvn> || is_sorted(h) is wrong for that code
<zamn> it is?
<zamn> oh
Yoric has quit [Read error: Connection reset by peer]
<zamn> that was our prior solution
<zamn> wasn't it
<mrvn> yes, when n == 1 the new h will be sorted
<zamn> # eval_moves(b, [b], 1);;
<zamn> - : int list list list = [[[0; 1; 2; 3]; [1; 0; 2; 3]]]
<zamn> yay
<mrvn> ((n > 0) and (is_sorted(h)))
<mrvn> Not necessary but cuts down the search time
<mrvn> (for too big n)
Neros has quit [Read error: Operation timed out]
<zamn> but how do i fix it for <= n solutions
Yoric has joined #ocaml
<mrvn> zamn: you don't. The exersize says length n, not length <= n
<zamn> but the tests they are running
<zamn> are on <= n
<mrvn> but if you must then in eval_moves test for is_sorted(b) first and only check n if b is not sorted
<mrvn> if is_sorted(b) then [endlist] else if n > 0 then check_moves(make_moves b, endlist, n)
<mrvn> else []
manizzle has quit [Ping timeout: 245 seconds]
<mrvn> zamn: my solution to the puzzle, finding one of the shortest possible solutions: http://paste.debian.net/hidden/e17998a4/
<mrvn> Takes a while to do 5x5 with 63 moves
Neros has joined #ocaml
<mrvn> that would probably not finish with your approach.
Yoric has quit [Read error: Connection reset by peer]
nikki93 has quit [Remote host closed the connection]
<mrvn> zamn: That's just for comparison. Doesn't realy solve your exercise.
<zamn> lol yeah
<mrvn> wrote that years ago.
<zamn> well you're my savior right now :D
<zamn> except i have one more failure now
<mrvn> well, enough saving for today, the bed is calling.
<zamn> noo 1 more case x_x
nikki93 has joined #ocaml
<zamn> i cant do it alonee
<mrvn> zamn: good.
<zamn> x_x
malo has quit [Quit: Leaving]
<mrvn> I hate that he is teaching you foo(x,y) syntax. You shouldn't pass arguments as tuples. Its slower and breaks partial aplications.
<mrvn> Its ocaml, not c.
<mrvn> n8
<zamn> night!
steshaw has joined #ocaml
<zamn> thanks for the help :)
Yoric has joined #ocaml
caseyjames has joined #ocaml
<caseyjames> I'm running toplevel in emacs. Is there anyway to 'open' a source from another file in the same directory? I tried #use "topfind";; #require "note";; but its giving me nothin