<Demitar>
Is that a "we don't want to know" silence or a "we might comment if you paste" silence? ;-)
mrsolo_ has quit [Read error: 110 (Connection timed out)]
cjohnson has quit [Read error: 110 (Connection timed out)]
cjohnson has joined #ocaml
pattern has quit [Network is unreachable]
yauz_ has joined #ocaml
yauz has quit [Read error: 60 (Operation timed out)]
ne1 has quit ["To understand recursion, you must first understand recursion."]
monotonom has joined #ocaml
cjohnson has quit [Read error: 104 (Connection reset by peer)]
pattern has joined #ocaml
weitzman is now known as weary
<jdrake>
if I do: # Random.self_init;; and outputs: - : unit -> unit = <fun> it hasn't ran the function has it
<Riastradh>
Random.self_init is simply a qualified name that happens to refer to a function.
<jdrake>
will # Random.self_init ();; actually call it?
<Riastradh>
Given that it's a function that takes an argument of type unit, and () is the only value of type unit, what do you think?
<jdrake>
i would think yes, but I do not know for sure
<Riastradh>
Why don't you try it and find out?
<jdrake>
i have tried it
<jdrake>
its kind of difficult to see when you aren't used to what it is doing
<jdrake>
or what it outputs
<jdrake>
i will assume that it does work based on the output
weary has quit [Read error: 60 (Operation timed out)]
Herrchen_ has joined #ocaml
Herrchen has quit [Read error: 60 (Operation timed out)]
mrsolo_ has joined #ocaml
debona|r has left #ocaml []
debona|r has joined #ocaml
debona|r has quit [Client Quit]
debona|r has joined #ocaml
monotonom has quit ["Don't talk to those who talk to themselves."]
<mflux>
hm, figured out (didn't try) a way to get any element of hashtbl: Hashtbl.iter + exception
<mflux>
it would be more elegant if Hashtbl itself were to provide something like that though, perhaps in the form of an iterator ;)
vezenchio has quit ["For more on this, consult your local linguistics professor. Yell "prescriptivist" at the top of your voice, and one or two sh]
<debona|r>
my god, the Using, Understanding, and Unraveling The OCaml Language certainly isn't documentation for beginners
jason__ has quit ["Client exiting"]
jdrake has quit [Read error: 60 (Operation timed out)]
<Demitar>
debona|r, if you're new to the language it is. Not if you're new to programming altogether.
<Demitar>
In general much stuff about functional programming seems to be written by computer scientists for computer scientists. :)
<debona|r>
Demitar: I'm not new, but it's quite heavy right away
<debona|r>
and I'm not a CS
<debona|r>
so maybe that's why
<debona|r>
I read the tutorial in the topic already
<debona|r>
readning the ocaml book now
<Demitar>
The OCaml book is great. When I first came into contact with OCaml (first venture into functional programming as well) I just couldn't wrap my mind around it. :) But it's a language that sticks... :)
<debona|r>
me neither, but that book helped a lot
<Demitar>
(I was learning ocaml from the manual. And if you're not used to it, quite a few things can make you wonder. Currying combined with the unit value can be greatly confusing. :)
<debona|r>
I looked at it several times actually
<debona|r>
then I saw the book in the topic
<debona|r>
and read it and finally understood
<debona|r>
goodnite
debona|r has left #ocaml []
_fab has joined #ocaml
_fab has quit [Read error: 54 (Connection reset by peer)]
_fab has joined #ocaml
Herrchen_ is now known as Herrchen
<Herrchen>
hi
<Demitar>
Hello Herrchen.
mrsolo_ has quit [Read error: 104 (Connection reset by peer)]
shawn_ has quit [Read error: 110 (Connection timed out)]
shawn has joined #ocaml
shawn has quit [Client Quit]
shawn has joined #ocaml
shawn has quit [Read error: 104 (Connection reset by peer)]
<ita>
i wonder .. if i define type seg={x1:int; x2:int; next:seg ref}, how do i declare something of type seg ?
<mellum>
Usually, you don't declare types explicitely.
shawn has joined #ocaml
<ita>
so it is better do declare something like : seg={x1:int; x2:int; next:a' } ?
<mellum>
I don't know, since I have no clue what it is you want.
<ita>
i want to make some sort of doubly linked list
<ita>
i think i'll do it in c then - i need something really fast
<mellum>
It won't get magically faster from doing it in C.
<mellum>
In fact, doubly linked lists will likely be slower in C, since heap management is less efficient.
<ita>
that's what i thought .. but the same algorithm, my implementation in ocaml is slower than the one in c++ (c++ without any particular optimization, using new/deletes at the wrong places, etc)
<Demitar>
What is it that needs a doubly linked list exactly?
<ita>
it is a list of segments, and i have to go through it several times
<ita>
i have tried with stacks (in ocaml) and the result was 10 times slower than with a linked list
<ita>
Herrchen: good idea, (though i am not sure to understand everything) i'll investigate
<mellum>
Does anybody know why the "extlib" ExtString module contains a module called "String" instead of all stuff directly?
Lemmih has quit [niven.freenode.net irc.freenode.net]
Lemmih has joined #ocaml
pac_away has joined #ocaml
pac_away is now known as pac_
weitzman has joined #ocaml
Hipo has quit [Read error: 104 (Connection reset by peer)]
jdrake has joined #ocaml
weitzman has quit [Read error: 60 (Operation timed out)]
<jdrake>
i could use some input on this code: http://rafb.net/paste/results/OqUcqn75.html I use the gd library binding with ocaml, but it doesn't output any files when ran. No exceptions either. I could also use input on code style.
weitzman has joined #ocaml
<jdrake>
found a problem
arnolt_ has joined #ocaml
<arnolt_>
where exactly is: "line 502, characters -72--44:" ?? (This seems to be leftwards off my screen, no? ;) )
<ita>
arnolt_: if you use vim, :make will bring you to the position of the error (should work in emacs too)
<arnolt_>
hm, currently i don't .... thanks anyway... but what does that mean? counting characters backwards?
Banana has quit [Read error: 110 (Connection timed out)]
Hipo has joined #ocaml
<jdrake>
http://rafb.net/paste/results/Sv25Xs19.html actual code with a mystery to me: line 14 gets called 5 times, but outputs the same thing everytime even though it is using Random.int. Any ideas
<cDlm>
jdrake: this defines a pair of ints
<cDlm>
not a function giving a new pair at each call
<jdrake>
hmm, that would be a problem
<cDlm>
s/would be a/is the/
ita has quit ["later all"]
pac_ has left #ocaml []
<jdrake>
how would I turn that into a function? The only thing I am seeing that is even close is 'function' but that looks like a fancy match statement
<cDlm>
just the same you define functions at the top level... it just needs an arg of type unit such as in let f () = Random.int 42
<jdrake>
so a function absolutely needs input then
<cDlm>
no
<jdrake>
so you can make a function with no parameters?
<cDlm>
() is not really a parameter...
<jdrake>
to my eyes it does
<jdrake>
even if it doesn't actually do anything for it
<cDlm>
well it is one but since it doesn't give any information... you can see it as just applying the function to nothing
<jdrake>
is there any code formatter for ocaml?
<mflux>
it's a funny non-orthogonal thing that you can write method foo = Random.int 42, which is different from method foo () = Random.int 42 (but when properly called does the same thing, it isn't immediately evaluated)
<mflux>
anyway, I really think () is a parameter even if it passes nothing
<mflux>
you can write let foo () () () = 42 for instance
<mellum>
It's simply pattern matching.
<mellum>
Nothing magic about ().
pac_away has joined #ocaml
pac_away is now known as pac_
vezenchio has joined #ocaml
jdrake has quit [Read error: 60 (Operation timed out)]
weitzman has quit [Read error: 60 (Operation timed out)]
maihem has joined #ocaml
weitzman has joined #ocaml
mrsolo_ has quit [Read error: 60 (Operation timed out)]
pac_ is now known as pac_aw
jdrake has joined #ocaml
yauz_ is now known as yauz
pac_aw has left #ocaml []
<mellum>
Grr, I really want a "break" in Ocaml sometimes
<mellum>
and a goto!
<mflux>
you've got raise ;)
<mflux>
which can be thought as a structured goto, ie. usable for all the cases goto should be used only for either ;)
jdrake has quit [Read error: 110 (Connection timed out)]
<mellum>
But it has lots of overhead.
<pnou>
premature optimization is the root of all evil :)
<mellum>
pnou: Well, I'm solving an NP-hard problem, so optimization is important ;)
<mflux>
how fast or slow are ocaml exceptions?
<mflux>
I'm just wondering as some documentation really does suggest to use an exceptino to break out of a for loop
<mellum>
Well, certainly faster than c++ ones. But probably not ideal for an inner loop
<mflux>
and I recently figured out the fastest way to get any (doesn't matter which) element from a hash would be Hashtbl.iter ( fun x -> raise Foo x ) bar
jdrake has joined #ocaml
<ronwalf>
mflux: That's scary
<mellum>
Hm. I can't think of a better way, either
lam has quit [Read error: 60 (Operation timed out)]
<ronwalf>
Though, I guess that's a general techinque for iter functions?
lam has joined #ocaml
<mflux>
it is :-o
<mflux>
ehm, I mean "it is ?-o"
weitzman has quit [Read error: 60 (Operation timed out)]
<ronwalf>
This is the type of problem that's easy with Python's generators
<ronwalf>
But Lazy gives us much the same thing?
<pnou>
hashtbl are not supposed to support this kind of operations, that's not so suprising that you must use a trick
<ronwalf>
no, maybe not
<pnou>
Python's generators ?
<ronwalf>
The yield syntax
<ronwalf>
I don't think it translates to fp very well...
<Riastradh>
Partial continuations would allow for more powerful and general control constructs than Python's generators, without necessitating the baggage of full continuations.
<ronwalf>
I would like continuations more than generators :)
<Riastradh>
Generators are a particular limited application of partial continuations.
<ronwalf>
I've always wondered why stackless python hasn't won out, adding continuations seems like a big win
<ronwalf>
Do you have a pointer to partial continuations?
<ronwalf>
(won out over the normal python interpreter, that is)
<mellum>
Riastradh: does any language implement them? Sounds interesting.
jdrake has quit [Connection timed out]
monotonom has joined #ocaml
<Riastradh>
mellum, they and numerous variations of them have been implemented numerous times in Scheme.
<Riastradh>
And SML.
<Riastradh>
...existing implementations of Scheme and SML, that is, not in vanilla Scheme and SML as libraries.
<mflux>
pnou, not supposed to?
<mflux>
pnou, says who?-)
<mflux>
pnou, it is extremely useful in certain cases
<mflux>
pnou, such as: you iterate a graph, removing visited nodes from the hash as you go
<mflux>
and after not finding any neighbours you get a new node left in the hash to continue from
<mflux>
and it's not like it is difficult for map or hash to retrieve such a list
<mflux>
hmh, a list, or any element
<mflux>
it's just that they don't provide any means of iterating only part of the structure: it's all or nothing-kind of deal
<pnou>
i didn't say it's not usefull, but i'm not suprised that this operation is not provided by a hashtable implementation
<mflux>
hmm.. are those generators much more useful than something like iterate (new range 1 10) (fun x -> Printf.printf "%d\n" x) would be? nicer syntax?
<mellum>
Riastradh: does any language implement them? Sounds interesting.
<Riastradh>
mellum, er, I already answered that.
<mflux>
of course that fun-part is not required due to currying ;)
<Riastradh>
Only if you can verify that printf won't perform any bogosity with currying in that instance.
<mflux>
well, if running it counts as verifying then yes
<mflux>
anyway, that form isn't as useful as it doesn't use 'yield', but instead a method that just returns the next value
<mflux>
so you need to restructure the code
<ronwalf>
mflux: generators give you a more control over execution. You don't have to evaluate them fully, and you can pause execution for as long as you like
<mflux>
in a functional language one would hope that generators could be 'automatically' generated from certain code
<mflux>
for example List.iter (..) (generate_a_long_list ()) would be able to evaluate the latter function simulatenously anyway
<mflux>
that cannot be done if it is not guaranteed that the functions don't have unforeseen side effects though
<mflux>
but, it would be cool nevertheless
<mflux>
and with multiple processors it could automatically be threaded ;)
<mellum>
Riastradh: sorry. I shouldn't hit random cursot keys
<Riastradh>
mflux, you can do that with non-strict functional languages like Haskell. Otherwise, you'd be better off specifying a folding enumerator protocol for everything that has enumerable elements.
<ronwalf>
Can you also do this with Lazy?
<Riastradh>
Yes, but folding enumerators are inherently superior. (although the superiority depends on having partial continuations! (or full continuations to simulate partial continuations))
<Riastradh>
Full continuations as in full CALL/CC or partial/composable continuations as in shift/reset or Queinnec & Moreau's partial continuation operators.
<Riastradh>
Oleg uses full continuations with CALL/CC to simulate partial continuations in his articles there, but using real partial continuation operators simplifies the code a great deal; don't be intimidated by what it appears is necessary to, as Oleg says, 'invert' a folding enumerator.
weitzman has joined #ocaml
gim has quit [Read error: 110 (Connection timed out)]
mattam_ has joined #ocaml
mattam has quit [Read error: 110 (Connection timed out)]
jdrake has joined #ocaml
_n0cte_ has joined #ocaml
_n0cte_ has left #ocaml []
CosmicRay has joined #ocaml
shawn has joined #ocaml
<jdrake>
in my code: http://rafb.net/paste/results/QJKF6V86.html line 16 to 19, it recurses, and when I try it for a million times I have a stack overflow with the bytecode compiler (seg fault on optimized). Shouldn't that be tail optimized?
gim has joined #ocaml
<Riastradh>
Shouldn't what be tail optimized?
<mattam_>
there's a ::
mattam_ is now known as mattam
<mattam>
generate_stars i suppose
<Riastradh>
generate_stars is not called recursively in a tail position with respect to the previous call to generate_stars.
<Riastradh>
It's called in a tail position with respect to the match, but after the result of the match is collected, there's, as mattam said, a call to ::, which means that generate_stars was not called in the tail position of generate_stars.
<jdrake>
is there any way of fixing it?
<Riastradh>
I doubt you need the list to be in the particular order in which you're currently building it, so you could build it in reverse and use an argument to generate_stars for an accumulator.
<jdrake>
murr in #macdev is recommending that
<jdrake>
not exactly sure how his code is working though
<Riastradh>
He uses OCaml?
<jdrake>
he is writing it based on my code i think, he is a little rusty with ml i beleive
<mattam>
let rec aux accu = function 0 -> List.rev accu | n -> aux (f n :: accu) (pred n), with f being generate_star. Maybe the imperative version would suit him better.
<Riastradh>
mattam, you don't need to reverse it at the end.
<mattam>
well, yes that's optional
<jdrake>
i am having trouble placing the 'function' keyword from what I know, i saw a few examples that looked like a match statement, but not sure
<Riastradh>
function x -> y | p -> q | a -> b
<Riastradh>
is equivalent to
<Riastradh>
fun mumble -> match mumble with x -> y | p -> q | a -> b
<jdrake>
if I had: let rec generate_stars count acc = ... could I use that form?
<Riastradh>
?
<jdrake>
how would I use 'function ...' (if I can)
<mattam>
you want the argument you pattern-match on last
<Riastradh>
You'd want to write:
<mattam>
so gen_starts acc = function (pattern on count)
<Riastradh>
let rec generate_stars count = function
<jdrake>
in the docs for Random it says: "Random.int bound returns a random integer between 0 (inclusive) and bound (exclusive). bound must be more than 0 and less than 2^30." But should that be (2^30)-1? Doesn't an int only use the highest bit for pointer information?
<jdrake>
correction
<jdrake>
'But should that be (2^31)-1? "
<pnou>
int are signed
<jdrake>
ah
CosmicRay has quit ["Client exiting"]
cjohnson has joined #ocaml
tautologico has joined #ocaml
<tautologico>
hi
monotonom has quit [Read error: 104 (Connection reset by peer)]
monotonom has joined #ocaml
<tautologico>
is there a standard function to split a string to a list of chars ?
<jdrake>
yes I believe so
<jdrake>
let me check
<jdrake>
maybe not
<jdrake>
i thought i did it once but don't see it in my surviving code
<tautologico>
there are explode and implode in sml
<tautologico>
but I think they don't exist in ocaml
<tautologico>
there is no direct way to reverse a string, it seems
<tautologico>
but it is easy to write these functions... I just hoped they were available in the standard libs
<jdrake>
well i guess they aren't
<tautologico>
nope
weitzman has quit [Read error: 60 (Operation timed out)]
weitzman has joined #ocaml
jdrake has quit [Remote closed the connection]
jdrake_ has joined #ocaml
maihem has quit ["Read error: 54 (Connection reset by chocolate)"]
cjohnson has quit [Read error: 110 (Connection timed out)]
cjohnson has joined #ocaml
<jdrake_>
is it possible to get the garbage collector to delay its operation, i have a program that 50% of the time is being taken by the garbage collector
<Riastradh>
You'd rather let it overflow the heap first?
<jdrake_>
well I would first like to see if there is an improvement by turning it off or delaying it
<cDlm>
how do you measure the time in GC ?
<jdrake_>
gprof
<jdrake_>
the two biggest hits:
<jdrake_>
37.3 1.23 1.23 _mark_slice [1]
<jdrake_>
10.0 1.56 0.33 _sweep_slice [2]
<Riastradh>
You could try using a bigger heap, although that would just make each garbage collector invocation more expensive.
<jdrake_>
it is possible to stop the garbage collector from invoking for a while?
<jdrake_>
sort of an on and off switch
<Riastradh>
jdrake_, that would cause the heap to overflow.
<Riastradh>
If the heap overflows, your program dies horribly.
<jdrake_>
would it make sense for a program like mine to use an Array instead of a list?