flux changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | OCaml 4.00.1 http://bit.ly/UHeZyT | http://www.ocaml.org | Public logs at http://tunes.org/~nef/logs/ocaml/
mort___ has quit [Quit: Leaving.]
orbitz has quit [Ping timeout: 252 seconds]
orbitz has joined #ocaml
_habnabit is now known as habnabit_
raichoo has quit [Quit: leaving]
chrisdotcode has joined #ocaml
osnr has joined #ocaml
osnr has quit [Changing host]
osnr has joined #ocaml
emmanuelux has quit [Ping timeout: 245 seconds]
chambart has quit [Ping timeout: 240 seconds]
madroach has quit [Ping timeout: 248 seconds]
madroach has joined #ocaml
<LiesHidden> Is it possible to initialize an array with Array.init using the option type?
Watcher7 is now known as Watcher7|off
<LiesHidden> For instance, I want 3 indexes to be Some (true) or Some (false) but the rest I need initialized with None so I can set them later.
Neros has quit [Ping timeout: 252 seconds]
<bernardofpc> you can certainly do that in two steps, first an Array.init , then a loop setting the others to some other value
<LiesHidden> It's giving me an error on Array.make, though I'm using Array.init, so I'm wondering If I typed it wrong.
<bernardofpc> but "Some true" and "Some false" look a bit awkward, I think
<bernardofpc> Array.make 3 (Some true) ;; works nice for me
<LiesHidden> I'm using init so it will do it by the index
<LiesHidden> let cache = Array.init (max + 1) (fun n -> match n with | 0 | 1 -> Some false | 89 -> Some true | _ -> None);;
<LiesHidden> Written neater than that in my file, lol, but I just wanted to give you an idea of what I had
<bernardofpc> this works for me
<bernardofpc> (of course, I had to overwrite max to be an int, not a function
<LiesHidden> Oddly I'm getting Exception: Invalid_argument "Array.make".
<LiesHidden> sorry max is 10Million, lol
<LiesHidden> Oh wait, maybe that's why!?!?
<bernardofpc> are you using the toplevel
<bernardofpc> ?
<LiesHidden> What's an Array's max size?
<bernardofpc> this should not be the problem
<bernardofpc> I can create with 100 Mi elements
<bernardofpc> (in a short time)
<bernardofpc> takes some mem, though
<LiesHidden> Weird, I can't.... gives me invalid argument, even in the top level
<bernardofpc> let a = Array.make 100000000 4 ;;
<bernardofpc> (start with basics...)
<LiesHidden> I did that, gave me an invalid argument, just checked my Sys.max_array_length: 4194303 so apparently that's why
<bernardofpc> A wild guess is that Array.make then modifying just very few indexes is much better than array.init
<bernardofpc> int = 18014398509481983
<Cypi> bernardofpc : I guess you have a 64bits machine, and LiesHidden has a 63 bits machine
<Cypi> 32* I mean
<bernardofpc> or a Windows machine :p
<LiesHidden> No I'm on Mageia :P
<bernardofpc> (how does OCaml relate to Win / Mac / Lin split ?)
<LiesHidden> But yes, it's 32-bit *sighs* need to upgrade to 64 bit :P
<bernardofpc> well, then
<LiesHidden> My max int is apparently 1 billion, but my max array size is 4 mill, what's up with that? :P
<bernardofpc> probably it'll be better to have a different structure, though
<ousado> LiesHidden: signed 31 bit int
<bernardofpc> ousado: how's max_array_len determined depending on the architecture ?
<ousado> and an unsigned 32 bit one for array size. just a "guess" :)
<LiesHidden> I can see why, because it can use more memory to store the indexes.
<bernardofpc> ousado: I still don't understand why they are odd numbers ....
<LiesHidden> My architecture is 64 bit, but the OS I'm running is 32-bit, so, the OS determines that I can only use so much
<bernardofpc> and mine looks like it's using only 54 bits, not 64
<Cypi> bernardofpc : if you have 22 bits for you, you can represent integers from 0 to 2^22-1. I think you know that :p
<Cypi> (that's why it's odd)
<bernardofpc> yep, I get 2^54 - 1
<bernardofpc> Cypi: that's why the LENGHT is 2^22
osnr has quit [Quit: Leaving.]
<bernardofpc> unless it needs one for header information
<bernardofpc> but that's another issue
<LiesHidden> Guess I'll have to use a List of Tuples (int, boolean)
<bernardofpc> I'm still puzzled why OCaml takes 10 bits out of the architecture to decide arr_len
<bernardofpc> LiesHidden: a Hashtable might be *way* better if the int's are unique
<bernardofpc> and in fact, that is even simpler with two Set's, one for true, another for false
<LiesHidden> they are.. the numbers between 1 and 10,000,000.... hmm or I could use the index of a List, and just store the boolean :D
<bernardofpc> (and if it's in none, then it's None in your Array representation)
<Cypi> I'm not an expert in representation of datas in OCaml. But I think there is a one-byte header, then the size of the array, then 2 bits for the GC, all that in one word
<bernardofpc> everything depends on how many numbers are *indeed* stored
<bernardofpc> 2 bits for GC ?
<bernardofpc> wasn't it just one ?
<bernardofpc> (hum, nevermind, it's another stuff)
<LiesHidden> I wanted to cache already found numbers, that could be found by doing the loops, so I can ignore them when I get to them later, if you know what I mean. That's why I wanted true for the ones I need, false for ones I've found but don't need, and None for ones I haven't seen yet
<bernardofpc> Note on 32 bit platforms, this is 22 bits long, which is the reason for the annoying 16 MByte limit on strings (16 MBytes = 4 M-words = 222 words). Solution: use a 64 bit platform for serious OCaml. -> Sad to hear
<bernardofpc> LiesHidden: think about the Set solution, it's probably much more meaningful
<bernardofpc> let neededmap = ... ; let ignorable = ... ;
<bernardofpc> and do post links to whatever you're working on, it will help people understant the *global* problem, not a micro-issue
<LiesHidden> Actually, Hashtbl seems to be working quite well as long as I can filter out the falses when I reach the end.
<LiesHidden> Project Euler problem 92 :)
<bernardofpc> hum
<bernardofpc> I see 10 Mi
<bernardofpc> but probably you only need 9^2 * ndigits
<bernardofpc> (in your array)
q66 has quit [Remote host closed the connection]
<LiesHidden> I know, once I get the chains found, I can map the chains and return true if they reach 89 or false if they reach 1, hence the Array, since it's mutable
<Cypi> Actually, your array's size shouldn't be more than something like 567, if you think of it.
<Cypi> (I mean, this solve this problem specifically)
<Cypi> (to solve*)
<LiesHidden> I figured when I reach the number in the main loop, I could check the array, if it's set, return that, else I'd start the chain expression on it, and map it to the array in case I reach a number in the chain again later in the main loop
<bernardofpc> Cypi: why not 486 ?
<bernardofpc> hum, my bad
<Cypi> :)
<bernardofpc> (nice numbers in numerology-wise setting)
<LiesHidden> Well, I can find the answer easily enough, but I want to program it, for my own benefit :P
<bernardofpc> LiesHidden: you have a math proof of the final value ?
pippijn_ has joined #ocaml
pippijn_ has quit [Client Quit]
<Cypi> Of course, but Project Euler is all about reducing the problem so that the programming is efficient. So think about twice, so that you don't memoize too much stuff.
<Cypi> +it
<LiesHidden> I was going to map the chains to reduce the number in the main loop, if I've already done it in another chain, it'll reach the same answer as the other, you're saying that won't be efficient though?
<Cypi> Yes, this idea is good. But what I'm saying is that past a certain number, the answers you're computing are useless for future computations. So you don't need to memoize them.
<bernardofpc> Cypi: memoize is perhaps not clear
<LiesHidden> I know what memoize means lol
darkf has joined #ocaml
gnuvince has quit [Remote host closed the connection]
<bernardofpc> humpf, biten by closures
<LiesHidden> Hmm, is it possible to find all based on what it's bound to in a Hashtbl?
osnr has joined #ocaml
osnr has quit [Changing host]
osnr has joined #ocaml
gnuvince has joined #ocaml
osnr has quit [Client Quit]
gnuvince has quit [Read error: Connection reset by peer]
gnuvince has joined #ocaml
<bernardofpc> are fold_left / fold_right tail-recursive over Array ?
<LiesHidden> I think fold_right is, but not fold_left, if it's the same as List
<LiesHidden> correction, the other way around according to inria.fr
<LiesHidden> But again, that's for List, not Array, it doesn't say under the Array page
<bernardofpc> exactly
<bernardofpc> note that since Array's have random access, nothing prevents it from being tail-rec from both ends
<LiesHidden> Indeed
<bernardofpc> 12.79s for 100_000_000, not bad
<LiesHidden> o.O
osnr has joined #ocaml
osnr has quit [Changing host]
osnr has joined #ocaml
<bernardofpc> 1.66s in C
<LiesHidden> Where you compiling with OCaml, or top level?
<bernardofpc> (somehow expected, because C ints are much faster because they are not 2n+1, and also because they're 4 not 8)
Neros has joined #ocaml
<bernardofpc> to get timings, ocamlopt
<bernardofpc> then time ./a.out
<LiesHidden> 8 minutes to fill my Hashtbl :/ (running time ocaml prob92.ml) *sighs*
<bernardofpc> well, that's because your Hashtbl is too big ;-)
<bernardofpc> (you're memoizing too much, probably)
<LiesHidden> lol that and I wasn't caching what I already had when i found a match
<LiesHidden> for instance if I reached 44 and it found it in the table, i just returned (), I forgot I still needed to memoize the list that reached 44.... dur dur dur (that idiot moment lol)
<bernardofpc> are you french ?
<LiesHidden> No, American
<bernardofpc> "dur" means what, then ?
<LiesHidden> Nothing, really, when someone says "dur dur dur" that means that they realized they were being or doing something stupid.
<LiesHidden> which brought my time down to 3 and a half minutes... definite speed up, but not fast enough, and I still don't know how to get a count of only the 'true' values
pkrnj has quit [Ping timeout: 276 seconds]
pkrnj has joined #ocaml
pkrnj has quit [Remote host closed the connection]
yacks has joined #ocaml
gnuvince has quit [Remote host closed the connection]
<LiesHidden> Grr I did something wrong :/
t4nk293 has joined #ocaml
<t4nk293> whats the difference between the construct let fxn1 x = ... in let fxn2 y = ... in fxn3;; and let fxn1 x = .... and fxn2 y = ... in fxn 3;;?
<t4nk293> one uses "in" to connect multiple expressions and the other uses "and"
<t4nk293> i see both used... not sure what is correct
<LiesHidden> "and" is usually used for mutually recursive constructs, in is usually used to express something that will be used in something else, and is if they call each other, in is if one calls the other, but not the other way around.. at least that's how I understand it
<t4nk293> ic, but it seems like you can always use "and" in this case
<t4nk293> in both cases i mean
<LiesHidden> I think the difference is in how OCaml interprets each... and might take more resources than in... don't take my word for it though
LiesHidden has quit [Read error: Operation timed out]
bholst has quit [Ping timeout: 276 seconds]
bholst has joined #ocaml
gautamc has quit [Read error: Connection reset by peer]
pippijn_ has joined #ocaml
Neros has quit [Ping timeout: 261 seconds]
vbmithr_ has joined #ocaml
gautamc has joined #ocaml
adrien_oww has quit [Ping timeout: 276 seconds]
vext01 has quit [Ping timeout: 276 seconds]
jpdeplaix has quit [Ping timeout: 276 seconds]
vbmithr has quit [Ping timeout: 276 seconds]
pippijn has quit [Ping timeout: 276 seconds]
Cypi has quit [Ping timeout: 276 seconds]
Cypi has joined #ocaml
LiesHidden has joined #ocaml
<LiesHidden> Guess I'm gonna have to find another way to do this :/
<t4nk293> ic, ok thanks
vext01 has joined #ocaml
jpdeplaix has joined #ocaml
adrien_oww has joined #ocaml
<LiesHidden> anyone know much about maps? Can I create a map with an int boolean binding?
letrec has quit [Ping timeout: 264 seconds]
gnuvince has joined #ocaml
yacks has quit [Ping timeout: 245 seconds]
<LiesHidden> blah building my own table that allows me to search both keys and values was a bad idea lol
osnr has quit [Quit: Leaving.]
mattrepl has quit [Quit: mattrepl]
ben_zen has quit [Quit: wheeeeeeeeeeee]
<adrien> you want sql?
yacks has joined #ocaml
Yoric has joined #ocaml
Yoric has quit [Ping timeout: 240 seconds]
<flux> lieshidden, 'int boolean binding'?
<flux> you can create a map from integers to booleans
<flux> t4nk293, if you have a sequence of 'and' bindings without rec, the values cannot refer to each other
<flux> if they are defined with let .. in let .. then the next binding can always see the previous ones
Yoric has joined #ocaml
<LiesHidden> I tried to create a map from ints to booleans, but it failed, said it was expecting an int... but then I haven't used maps before, so I probably did something wrong
<flux> module IntMap = Map.Make(struct type t = int let compare = compare end)
<LiesHidden> I did that much
<flux> IntMap.add 42 false (IntMap.empty)
<LiesHidden> That's where it failed
<flux> works for me (TM) :)
<flux> # IntMap.add 42 false (IntMap.empty);;
<flux> - : bool IntMap.t = <abstr>
<LiesHidden> wait it might have failed somewhere else in the code....
<flux> btw, do you use vim or emacs?
<flux> if so, both of them have a way to find the types of expressions under your cursor
<LiesHidden> Right now? Neither, lol, I'm not comfortable enough with them to use them for deep work like this, I just use them when I'm trying to learn them. I like emacs a little better, btw
<flux> in emacs it is C-c C-t. it requires ocaml-mode to be installed, but works fine in tuareg mode. it also requires the files to be compiled with -dtypes
<flux> I've found it a very valuable tool when debugging type issues
<flux> maybe there is a way to have that in your editor as well..
<LiesHidden> Using kate right now, seems to work pretty well
<flux> apparently there is an ocaml plugin for kate, but it deals only with the toplevel
<flux> still probable useful, I use that as well in Emacs all the time
<LiesHidden> Yeah, there's a ocaml mode for it, that just pretty much provides syntax highlighting and auto complete
<LiesHidden> Now, can I search both keys and values with maps?
<flux> no, you need to have two maps
<flux> ..which can get a bit complicated in presense of duplicate values
<flux> well, you _can_ search maps for values but it's not going to be fast
<flux> basically you iterate through them and if you find the value, put a copy to a reference and bail out with an exception..
<LiesHidden> Maybe filter by value, then?
<flux> would work, you would do that with the fold function of Map
<LiesHidden> Like to return a list of all trues
<LiesHidden> or count them anyway
<flux> IntMap.fold (fun int bool rs -> if bool then rs + 1 else rs) the_map 0
<flux> but, off to make breakfast, happy hacking :)
<LiesHidden> *chuckles* thanx I'll give that a try
osnr has joined #ocaml
osnr has quit [Changing host]
osnr has joined #ocaml
cdidd has joined #ocaml
eni has joined #ocaml
eni has quit [Ping timeout: 264 seconds]
Yoric has quit [Ping timeout: 260 seconds]
ttamttam has joined #ocaml
mort___ has joined #ocaml
Nahra_ has joined #ocaml
Nahra_ has quit [Client Quit]
mort___ has quit [Quit: Leaving.]
Yoric has joined #ocaml
gnuvince has quit [Remote host closed the connection]
eni has joined #ocaml
gautamc has quit [Read error: Connection reset by peer]
gautamc has joined #ocaml
osnr has quit [Quit: Leaving.]
lizzin has joined #ocaml
cdidd has quit [Ping timeout: 248 seconds]
cdidd has joined #ocaml
tane has joined #ocaml
Kakadu has joined #ocaml
osnr has joined #ocaml
osnr has quit [Changing host]
osnr has joined #ocaml
ulfdoz has joined #ocaml
ousado has quit [Read error: Operation timed out]
Yoric has quit [Ping timeout: 240 seconds]
ousado has joined #ocaml
cdidd has quit [Ping timeout: 252 seconds]
cdidd has joined #ocaml
Yoric has joined #ocaml
chambart has joined #ocaml
ttamttam has quit [Remote host closed the connection]
rks is now known as Guest53516
Guest53516 has quit [Killed (hitchcock.freenode.net (Nickname regained by services))]
rks_ has joined #ocaml
weie has joined #ocaml
weie_ has quit [Ping timeout: 240 seconds]
Zeev has joined #ocaml
Neros has joined #ocaml
ggole has joined #ocaml
ollehar has joined #ocaml
chambart has quit [Ping timeout: 240 seconds]
rks_ has quit [Ping timeout: 276 seconds]
adrien_oww has quit [Ping timeout: 276 seconds]
stephe has quit [Ping timeout: 276 seconds]
gasche has quit [Ping timeout: 276 seconds]
stephe has joined #ocaml
rks_ has joined #ocaml
adrien_oww has joined #ocaml
gasche has joined #ocaml
foo808 has joined #ocaml
osnr has quit [Quit: Leaving.]
tane has quit [Quit: Verlassend]
ontologiae has joined #ocaml
yacks has quit [Ping timeout: 256 seconds]
foo808 has quit [Quit: leaving]
foo808 has joined #ocaml
Drup has joined #ocaml
ttamttam has joined #ocaml
Yoric has quit [Ping timeout: 260 seconds]
q66 has joined #ocaml
osnr has joined #ocaml
osnr has quit [Changing host]
osnr has joined #ocaml
ttamttam has quit [Quit: ttamttam]
osnr has quit [Ping timeout: 256 seconds]
yacks has joined #ocaml
eikke has joined #ocaml
milosn has quit [Remote host closed the connection]
eikke has quit [Ping timeout: 260 seconds]
osnr has joined #ocaml
osnr has quit [Changing host]
osnr has joined #ocaml
osnr has quit [Ping timeout: 256 seconds]
eikke has joined #ocaml
yacks has quit [Quit: Leaving]
mattrepl has joined #ocaml
pippijn_ is now known as pippijn
yezariaely has quit [Read error: Operation timed out]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
ulfdoz has quit [Ping timeout: 245 seconds]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
yezariaely has quit [Max SendQ exceeded]
yezariaely has joined #ocaml
jbrown has quit [Ping timeout: 256 seconds]
jbrown has joined #ocaml
Watcher7|off has quit [Ping timeout: 252 seconds]
Watcher7|off has joined #ocaml
tane has joined #ocaml
chambart has joined #ocaml
yacks has joined #ocaml
osnr has joined #ocaml
osnr has quit [Changing host]
osnr has joined #ocaml
letrec has joined #ocaml
osnr has quit [Ping timeout: 252 seconds]
ontologiae has quit [Ping timeout: 248 seconds]
chambart has quit [Ping timeout: 240 seconds]
gnuvince has joined #ocaml
ygrek has joined #ocaml
gnuvince has quit [Quit: Remember when men were men and regular expressions recognized regular languages?]
chambart has joined #ocaml
gnuvince has joined #ocaml
ygrek has quit [Ping timeout: 245 seconds]
talzeus has joined #ocaml
talzeus has left #ocaml []
ygrek has joined #ocaml
chambart has quit [Ping timeout: 260 seconds]
tobiasBora has joined #ocaml
ygrek has quit [Ping timeout: 245 seconds]
darkf has quit [Quit: Leaving]
ygrek has joined #ocaml
LeNsTR is now known as lenstr
ygrek has quit [Ping timeout: 252 seconds]
walter|r has joined #ocaml
walter has quit [Ping timeout: 246 seconds]
gnuvince has quit [Remote host closed the connection]
gnuvince has joined #ocaml
walter|r has quit [Quit: This computer has gone to sleep]
ulfdoz has joined #ocaml
walter|r has joined #ocaml
<jbrown> dumb GADT question: if I have a "list" type like: "type _ mylist = Empty : unit mylist | Node : 'a * 'b mylist -> ('a * 'b) mylist", is there any way of writing the equivalent of "List.nth" for it?
chambart has joined #ocaml
malo has joined #ocaml
contempt has quit [Disconnected by services]
contempt has joined #ocaml
yacks has quit [Remote host closed the connection]
ontologiae has joined #ocaml
iZsh has quit [Quit: Coyote finally caught me]
oriba has joined #ocaml
Zeev has quit [Ping timeout: 252 seconds]
ygrek has joined #ocaml
eikke has quit [Ping timeout: 252 seconds]
eni has quit [Ping timeout: 248 seconds]
ontologiae has quit [Ping timeout: 240 seconds]
Zeev has joined #ocaml
tane has quit [Quit: Verlassend]
jcao219 has joined #ocaml
chambart has quit [Ping timeout: 260 seconds]
ygrek has quit [Ping timeout: 245 seconds]
eps917 has joined #ocaml
eps917 has quit [Client Quit]
eps917 has joined #ocaml
shinnya has joined #ocaml
eps917 has quit [Client Quit]
contempt has quit [Ping timeout: 245 seconds]
contempt has joined #ocaml
<bernardofpc> I don't think so, your List.nth will have a hard time figuring out its own type
<bernardofpc> its argument's type ('a * ('b * .... )) and the consequent return type both depend on its first argument (n)
<bernardofpc> maybe you can have a functor that creates List.nth from a definite value of n
<bernardofpc> (math-wise, not sure whether it's implemented in OCaml)
bobry has quit [K-Lined]
lopex has quit [K-Lined]
ggherdov has quit [K-Lined]
IbnFirnas has quit [K-Lined]
es917 has joined #ocaml
es917 has quit [Client Quit]
es917 has joined #ocaml
ggherdov has joined #ocaml
bobry has joined #ocaml
Nahra has quit [Read error: Connection reset by peer]
lopex has joined #ocaml
Nahra has joined #ocaml
Nahra has quit [Changing host]
Nahra has joined #ocaml
Nahra has quit [Client Quit]
contempt has quit [Remote host closed the connection]
<t4nk293> is there a way to see docstring of a function in toplevel?
contempt has joined #ocaml
<t4nk293> for example if i wanna know how to use String.make, is it possible to find out in toplevel
Nahra has joined #ocaml
Nahra has quit [Changing host]
Nahra has joined #ocaml
<adrien> half of that will be given if you type 'String.make;;'
<adrien> it will only give the prototype but very often it's enough
<adrien> for something more advanced, I don't know; maybe utop has that
<Kakadu> If labeled arguments are used than prototype will be enough every time, imho
Yoric has joined #ocaml
jtoman_ has joined #ocaml
<jtoman_> I'm struggling with a strange bug (?) when calling from ocaml to c and then back to ocaml. When I try to *do* something with the value returned from the ocaml callback, my program segfaults
<jtoman_> However, if I simply return the value back to the OCaml program no problem.
<adrien> 100 chances out of 10, the C bindings are bad :-)
<Kakadu> :)
<jtoman_> You mean my C bindings?
<Kakadu> yeah
<Kakadu> Is a peace of code very big?
<jtoman_> Kakadu: that's what I thought too, so I tried to construct a super simple example.
<jtoman_> let me paste it somewhere.
<adrien> it's like in C: you can have as many NULLs as you want, your program will only crash when you dereference them
<Kakadu> I was thinking that my C binding OK about 100 times. And every time they sucks
<Kakadu> or past perfect, I don't know grammar:)
<jtoman_> It segfaults at the Tag_val line
<jbrown> bernardofpc: that's what I suspected, thanks!
<jtoman_> When I take it out and let the value return back to that match statements, success gets printed and life is good
<jtoman_> If it matters, this happens with ocaml 3.12 and with 4.00.1 (although it's possible I just compiled 4.0 wrong)
<Kakadu> Are you sure that it fails in `Tag_val(foo)`? Can you print foo before?
<jtoman_> Kakadu: I ran it in a debugger and gdb claims it's at that line. How do you want me to print it? printf("%u")?
<ggole> Is the value in question a tagged block?
<jtoman_> ggole: it's a variant with an argument
<Kakadu> #define Tag_val(val) (((unsigned char *) (val)) [-1])
<jtoman_> so I assumed so, let me double check by asserting Is_block
<ggole> Yeah, that should be a block
<jtoman_> ggole: just added an assertion and it's a block
<jtoman_> Well this is interesting
<jtoman_> printf("%p\n", (unsigned char*)ret); -> prints 0xffffffff9f1b2f40
<jtoman_> that printf comes just before the "call" to Tag_val
<adrien> was going to ask what caml_callback returns
<ggole> Oh
<ggole> type foo = Bar of int
<ggole> That constructor will be stripped
<ggole> Add another leg
<ggole> type foo = Bar of int | Unused of int
<adrien> hahaha
<jtoman_> Maybe I did it wrong, but it still seems to be segfaulting. Let me update the paste.
<jtoman_> updated: http://pastebin.com/gZAXY9eB
<jtoman_> there's also an assertion in there that asserts the return value is a block
<ggole> Lemme try
<jtoman_> ggole: thank you :)
<ggole> Hmm, what's the library name again?
<jtoman_> ggole: which library?
<ggole> The ocaml runtime
<ggole> Which I need to link with the C
<jtoman_> asmrun
<jtoman_> iirc
<jtoman_> I was able to compile that code by putting it in two files, test_cb.ml and test_stubs.c, and compiling with "ocamlopt -I /usr/include/caml/ ./test_stub.c ./cb_test.ml -o ./test"
<ggole> Oh, it knows how to compile C
<ggole> Great
<ggole> Print 0 success
<ggole> Hmm
<jtoman_> ggole: it works on your computer?
<ggole> Seems to
<jtoman_> are you on ocaml 4.00?
<ggole> Oddly, it seems to work even with the one-case variant
<ggole> No
<ggole> 3.11.2
<jtoman_> oh! hm, i wonder
<ggole> And I'm on a 32-bit machine
<jtoman_> aha, yeah I'm on a 64-bit machine
<jtoman_> I happen to have a 32-bit computer too, let me try it
<ggole> The interface should behave the same, though
<ggole> I don't think 64-bit ocaml does anything funny with variant representations that would screw it up: and in any case your assertion indicates the value is a tagged block.
<adrien> well, it doesn't have to be 64bit ocaml
<adrien> integer promotion in C can be fun
<bernardofpc> what's the "natural" way of "filling up an array" ?
<bernardofpc> (it's relatively important that it's ordered, and it increases from the far-away point of access)
<bernardofpc> (so a list that grows is terribly innefficient)
<jtoman_> Oh look at that, it works for me on my 32-bt machine.
<ggole> jtoman_, interesting
<ggole> bernardofpc: natural in what context?
<jtoman_> however, my 32-bit computer is using a different version of gcc, so it's possible that the problem is because of diff gcc behavior
<adrien> that seems less likely than the difference in bitness
<bernardofpc> ggole: nevermind, I forgot that Array's are mutable
<bernardofpc> too much thinking of imutable values in fun prog
<ggole> There's little scope for integer conversions there
<jtoman_> So, is this a bug then? Should I report it to the OCaml folks?
<ggole> Everything is a value or value *
<ggole> (In the call to printf maybe, but that would just print junk, not crash)
<bernardofpc> other question, though
<ggole> I'd check everything first
<bernardofpc> is it possible to "escape" from a "for loop" ?
<ggole> But yeah
<ggole> Yes, you can throw and catch
<ggole> There is no continue, break or goto though
<jtoman_> well, I took out the printf and it still segfaults
<jtoman_> okay, well, i'll see if i can find another 64-bit environment to test this on.
<bernardofpc> I'd need break more than throw, though
<ggole> What happens when you step through it with gdb?
<jtoman_> through my c code?
<ggole> Yeah
<jtoman_> uh, let me check
<ggole> Although it might be hard to see what with the representation of caml values being a bit odd to a C debugger
RagingDave has joined #ocaml
<jtoman_> (gdb) print (unsigned char*)ret -> 0xfffffffff7519f40 <Address 0xfffffffff7519f40 out of bounds>
Kakadu has quit [Ping timeout: 256 seconds]
<jtoman_> considering the cast to unsigned char is exactly what the Tag_val is doing...
<ggole> Hmm
<ggole> I'm not sure what to make of that.
<ggole> If I was doing this, I might look at the memory mappings and see if it's close to anything
<ggole> But a bug report might be the best path forward
ggherdov has quit [Changing host]
ggherdov has joined #ocaml
ggherdov has quit [Changing host]
ggherdov has joined #ocaml
<jtoman_> okay. ggole adrien, thanks a bunch for your guys' help. I'm happy to know I'm not crazy
gautamc has quit [Read error: Connection reset by peer]
gautamc has joined #ocaml
<ggole> No worries.
<adrien> this stuff isn't easy
<adrien> I spent a couple days on a bug with my own Char_val (there's none in ocaml by default)
<adrien> I had a char (8 bits) and then an int
<adrien> but char is signed by default so when you cast to an int which is wider, you keep the sign bit
<adrien> in my case however I wanted unsigned
<adrien> the sign bit ended somewhere that made the program jump at a completely crazy address
<adrien> worst thing is that when I made my Char_val, I thought "hmm, I should probably cast to (unsigned char) first; nah, I'll stay without for now and I'll remember that if something odd happens, I need the cast"
<adrien> ='(
<ggole> Good old sign extension
<jtoman_> a couple of days?
<adrien> not full time
<adrien> but it definitely took some time
<adrien> I went through the ASM generated by ocamlopt :D
<jtoman_> No I was referring to how little bugs like that always take the longest...
<adrien> ah
<adrien> well, my worst was finding a typo: lalbgtk instead of lablgtk: at least 2 hours, maybe around 4
<jtoman_> *wince*
vbmithr_ has quit [Ping timeout: 256 seconds]
<ggole> Ouch :D
<ggole> C makes it so easy to do something silly like miss a break or forget to init a variable
<ggole> Easy to waste time
vbmithr has joined #ocaml
<ggole> Hmm, somehow I got the idea that tags are removed from single-leg variants
<ggole> But they aren't
derek_c has joined #ocaml
shinnya has left #ocaml []
shinnya has joined #ocaml
shinnya has left #ocaml []
shinnya has joined #ocaml
shinnya has left #ocaml []
shinnya has joined #ocaml
shinnya has quit [Remote host closed the connection]
shinnya has joined #ocaml
shinnya has quit [Remote host closed the connection]
shinnya has joined #ocaml
ollehar has quit [Ping timeout: 248 seconds]
derek_c has quit [Quit: Lost terminal]
tane has joined #ocaml
habnabit_ is now known as _habnabit
jcao219 has quit [Ping timeout: 248 seconds]
vbmithr has quit [Ping timeout: 260 seconds]
Watcher7|off is now known as Watcher7
Watcher7 is now known as Watcher7|off
Watcher7|off is now known as Watcher7
<LiesHidden> From 3 1/2 minutes using maps, to just under 3 using Arrays (stopping at 567 and finishing based on the answers in there for both options)... I can't think of a way to speed this up to under a minute though...
ulfdoz has quit [Read error: Operation timed out]
gnuvince has quit [Ping timeout: 245 seconds]
emmanuelux has joined #ocaml
<bernardofpc> LiesHidden: try to time how long you take at each part of your program, viz the 567 part then the 10_000_000 part
cdidd has quit [Ping timeout: 246 seconds]
<LiesHidden> I'm pretty sure it's the 10Mill, but I'm not using a list, just iterating, adding the digits and finding it in the array, if true incrementing a counter
<LiesHidden> There's a function that is applied to all parts, that I think I can optimize a little, I'm debating on adding a small list of the squares of 0..81 instead of using the actual multiplication, just getting List.nth x squares.. and second, the function to turn it into a sequence of digits, I'm using string conversion, and back again... I think doing a mod then dividing by 10 in a small recursion might be more efficient, but I can't
<ggole> Is this a project euler problem or something?
<LiesHidden> yes, it's a project euler problem lol
<Watcher7> What problem number is it?
<LiesHidden> 92, I've solved it, but it takes 3 minutes, I'm trying to optimize it so it takes less than a minute
<ggole> And you are extracting digits by conversion to string? That's probably the place to look.
<LiesHidden> I'm fixing that now, plus adding a small list for the squares to save a little time on mulitplications
<ggole> As in an int list? Surely the mul will be faster.
<ggole> They are 6 cycles or so on recent machines.
<LiesHidden> We'll see if I get any improvement
<gasche> LiesHidden: have you profiled your program?
<LiesHidden> I'm running through the interpreter right now, not compiling it, but it shouldn't add that much overhead
<LiesHidden> of course, it can only use one thread of one core, which is probably part of why it's so slow lol
<gasche> I don't get it
<gasche> are you using bytecode compilation?
<gasche> (or did you build a native toplevel?)
<gasche> and how can you optimize some code if you have not profiled it?
<gasche> that's a guaranteed ticket for wasting time on code portions that don't need optimizations
<LiesHidden> As this is a learning project for me, I don't consider it a waste of time.
mathieui has quit [Ping timeout: 252 seconds]
<Drup> LiesHidden: you do realize there is at least one order of magnitude between bytecode and nativecode ?
<gasche> LiesHidden: the most important thing you should learn is to detect which part to optimize, and which part not to
mathieui has joined #ocaml
<ggole> I just wrote a pretty straightforward solution that finishes in ~2secs
<LiesHidden> I do, but if I can get it to run in less than a minute using the interpreter, then i can be assured that it will run even faster in nativecode
<ggole> No lookup arrays or any clever stuff
<ggole> So I'd just focus on writing good clean code that does things sensibly
<gasche> LiesHidden: what is the point of intentionally running your program the slow way?
<gasche> it just makes you wait three minutes before trying a new change to the code
<LiesHidden> *chuckles* not with the end process if goes over my time, i can just end it and try again
<gasche> frankly, it looks like you are doing this the wrong way
<LiesHidden> Possibly
<LiesHidden> The downside to trying to learn things on your own, you don't have someone to guide you to the right conclusions lol, which is why I'm in here, to get professional opinions on what I'm doing :D
jcao219 has joined #ocaml
<gasche> LiesHidden: well
<gasche> first, use native compilation to run your computation-intensive programs
emmanuelux has quit [Ping timeout: 246 seconds]
<gasche> there is no valid reason not to
<adrien> (unless you're on mips :P
<adrien> )
<gasche> (and frankly this "if it's fast in bytecode, it will be even faster with native compilation" looks like a bad modern remake of the joke about someone walking with an anvil in the desert)
<gasche> the second important thing about optimization
<gasche> is that most of the time, only a very small part of your code will be where the running time goes
<gasche> something like 90% of the time spent in 10% of the code
<ggole> Only ~5x slower for my run anyway
<gasche> so you need to use profiling tools to tell you where the critical parts are (humans are often rather bad at guessing this), and only optimize those
<ggole> That's quite respectable for an interpreter
<gasche> optimizing your command-line-argument processing code to death is stupid if your program spends a neglectible amount of time in it anyway
<ggole> That's less true of euler problems than real code, though
Yoric has quit [Ping timeout: 240 seconds]
<gasche> yes
<gasche> for toy problems
<gasche> (and Euler problems are a particularly bad kind of toy problems if you ask me, as they rely on cunning maths rather than good code)
<gasche> the critical section will typically be larger
<ggole> Yeah
<ggole> They are fun, but not really good programming practice
<LiesHidden> I enjoy the challenge of them... though it's pretty easy to get insights into the problems via a good google search
<gasche> but still, if what you learn playing with toy problems all day is "how to solve toy math problems", you wasted your time; you should try to practice in a way that's conductive to improving your programming skills at large
<gasche> and for that, respecting the idea of never optimizing before having done serious profiling is key
<ggole> I used to be really bad at that
<ggole> If I could see an optimisation, I just had to put it in
Tobu has quit [Ping timeout: 240 seconds]
<ggole> It was pretty horrible.
<ggole> And unclear code often leads to a lack of the clarity you need to see where the good optimisations are
<LiesHidden> I like to think my code is clear, but I just wrote it, 5 months from now, will I still think it is? lol
<ggole> So you can defeat yourself quite thoroughly
<Drup> LiesHidden: the answer to this question is *always* no
es917 has quit [Quit: es917]
<LiesHidden> Don't I know it lol, back when I was beginning programming (VB 5) I built a program, and years later went back to it to port it to something else, i forget what, and it took me awhile to understand what I was thinking with each part lol
<LiesHidden> Of course, those years I also didn't do much programming at all
<LiesHidden> Holy crap! changing from string conversion to the recursive mod and divide function decreased my time to 30 seconds (interpreted)!
<LiesHidden> 2 seconds native code :D
ggole has quit []
iZsh has joined #ocaml
jbrown has quit [Ping timeout: 276 seconds]
oriba_ has joined #ocaml
oriba has quit [Ping timeout: 245 seconds]
emmanuelux has joined #ocaml
RagingDave has quit [Quit: Ex-Chat]
vbmithr has joined #ocaml
tobiasBora has quit [Quit: Konversation terminated!]
yacks has joined #ocaml
yacks has quit [Ping timeout: 260 seconds]
malo has quit [Quit: Leaving]
ollehar has joined #ocaml
derek_c has joined #ocaml