cjeris changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/
Mr_Awesome has joined #ocaml
pstickne has quit [Read error: 104 (Connection reset by peer)]
pstickne has joined #ocaml
pstickne has quit [Read error: 104 (Connection reset by peer)]
pstickne has joined #ocaml
pstickne has quit [Read error: 104 (Connection reset by peer)]
pstickne has joined #ocaml
rturner has quit [Remote closed the connection]
Smerdyakov has quit ["Leaving"]
Mr_Awesome has quit ["...and the Awesome level drops"]
jkeith has left #ocaml []
smimou has joined #ocaml
ygrek has joined #ocaml
jlouis_ has quit [Remote closed the connection]
Submarine has quit [Remote closed the connection]
haelix has joined #ocaml
ygrek has quit [Remote closed the connection]
ygrek has joined #ocaml
skal has joined #ocaml
MrFrankly has joined #ocaml
MrFrankly has quit [Client Quit]
joelr1 has joined #ocaml
<joelr1>
morning
<joelr1>
has anyone checked out the release310 branch of ocaml?
<joelr1>
from cvs
joelr1 has quit []
mqtt has joined #ocaml
<mqtt>
hello,
<mqtt>
does anyone have an idea why this (http://rafb.net/p/iQjYbR97.html) program loops infinitely? It shouldn't, and i spent a whole day trying to figure out why... thx in advance!
<mqtt>
the problem seems to be that each time the graph is passed to id_div2, it gets bigger (in number of nodes).
<mqtt>
but i'm not sure yet...
<flux>
most curious indentation
<flux>
or maybe my browser displays it wrong
<flux>
I'll try reading that again from a proper terminal :)
<flux>
(later)
<mqtt>
flux, ?? it's tuareg-mode standard indent...
<flux>
ok, it's the mobile web browser then
<flux>
no line is longer than 10 chars or so
<flux>
ah, mini-rendering-mode
<ygrek>
how can I convert int to string?
<ygrek>
to_string n says unbound to_string?
<ygrek>
"to_string n" says "unbound to_string"
<ygrek>
string_of_int is ok. Please help - how can I load ml source in ocaml interactive on Windows?
<ygrek>
when I run ocaml a.ml it just exits cleanle
<flux>
#use "a.ml"
descender has quit [zelazny.freenode.net irc.freenode.net]
eradman has quit [zelazny.freenode.net irc.freenode.net]
<ygrek>
use "a.ml";;
<ygrek>
^^^
<ygrek>
Unbound value use
<ygrek>
got it
<ygrek>
that # was not a prompt
descender has joined #ocaml
eradman has joined #ocaml
<flux>
mqtt, you use structural comparison with self-recursive functions
<flux>
mqtt, that will cause an infinite loop
<flux>
make that data structures, not functions
<flux>
mqtt, so you'll need to write your own graph comparison function and use that
<flux>
unless physical equality comparison is enough for you (I don't think it is) - the == -operator
<flux>
mqtt, btw, id_div2 could be refactored into something like (graph -> graph) -> graph -> graph, which could be called like map (fun g -> { g with id = g.id / 2 }) g
<flux>
mqtt, personally I would probably use something like type id = int module IdMap = Map.Make(struct type t = id let compare = compare) type graph = id list IdMap.t
<flux>
albeit your approach has its advantages
rturner has joined #ocaml
<mqtt>
flux, thx and sorry for the delay, i didn't see your messages.
<mqtt>
flux, i can't change my datastructure (the project is too advanced for that), but i doesn't seem to be the problem to caml to compare graphs using =, what i don't understand is that the id_div2 function seems to enlarge the graph passed: that seems to be why the fixpoint doesn't halt... I thought it was a problem with the "seen" variable... do you have a clue on why it's acting like this?
<mqtt>
(sorry for my poor english...)
<mrvn>
(fun n -> try (List.find (fun s -> s==n) !seen)
<mrvn>
with Not_found -> id_div2_rec n) node.succ in
<mrvn>
That one seems the wrong way around.
<mqtt>
mrvn, ??? what do you mean?
<mqtt>
my reasoning was: if i already saw this node, return it (from 'seen'), if not, go recursively into it. isn't it correct?
<mrvn>
You store the unaltered nodes in !seen. When you find a "seen" node you give back the unaltered one. When you find a new node you alter it.
<mrvn>
You need a (id * node) Hashtbl
<mqtt>
ok... errr let's see...
<mrvn>
id of the unaltered node -> altered node
<mrvn>
Does a node ever have itself in the succ list?
<mqtt>
could be possible yes
<mqtt>
why?
<mrvn>
Then you have to check that first, then check if the node is in seen and last add (unaltered, altered) to seen.
<mrvn>
You can use a assoc list or better a hashtbl.
<mqtt>
i don't exactly see what you mean by altered. there isn't any mutables here...
<mrvn>
the { id=node.id/2; succ=succ }
bluestorm_ has joined #ocaml
<mqtt>
mrvn, your right!
<mrvn>
print_string "iteration\n"; flush stdout;
<mrvn>
That one is missing "%d" and n
<mqtt>
mrvn, oh god! how did i miss that!
<mqtt>
i know, it was a quick way to see what was the infinite loop
<mrvn>
in main() too.
<mrvn>
ah, never mind.
<mrvn>
Why do you have an id:int if it is not kept uniqe?
<mqtt>
mrvn, but why do i need to store the id _and_ the node in 'seen'? isn't the node enough?
<mrvn>
mqtt: id doesn't work since it is not unique. You need old node and new node.
<mqtt>
actually the id was just a way to store informations in a node. in the real code, there are more informations in a node. it should be called 'content' not 'id'...
<mqtt>
i try to fix this first. thanks a lot for the help, it's been very very useful!
ygrek has quit [Remote closed the connection]
<mrvn>
let rec node2 = { id=node.id/2; succ=(Hashtbl.add seen node2; List.map (fun n -> try Hashtbl.find seen n with Not_found -> id_div2_rec n) node.succ;} in node2
<mrvn>
Try that in id_div2_rec with seen a Hashtbl.
<mrvn>
But I think you can't use nod2 as function argument whil constructing it.
<mrvn>
This kind of expression is not allowed as right-hand side of `let rec'
<mqtt>
that's right
<mqtt>
i think i have to make succ a mutable field.
<mrvn>
I think you can't write id_div2 without it.
<mqtt>
i thought too, but i never found a proper functional way to do it.
<mrvn>
You should assign unique IDs to each node and make an ID list instead of a graph list.
<mrvn>
And a graph is then a id->node Hashtbl.
<mrvn>
That removes the circular references
<mrvn>
Or you can make the content mutable and modify it in place while leaving your succ lists as is.
<mqtt>
i can't change the datastructure. i'll try the second way
<mrvn>
you will have to change something.
<mqtt>
i can add a mutable to the succ list, but i can't have the graph represented as a assoc list. it must be a recursive data type... sadly
<mqtt>
but it's an interesting func programming problem, isn't it?
mqtt has quit ["Quitte"]
<mrvn>
One quite impossible to solve without mutable.
<mrvn>
I find that TWT makes changing code difficult when you have to reindent something.
Oxylin has joined #ocaml
<ita>
mrvn: it is so much easier to leave the code unindented indeed :-)
<mrvn>
Easier to just press <tab> in every line and have xemacs indent it right.
mikeX has joined #ocaml
<mrvn>
And worst of all: What if people mix tab and spaces.
<ita>
there is a mode for preventing mixed tabs and spaces
<ita>
looking at python, this is not a problem in general
<hcarty>
The lack of toplevel support is also unfortunate
cjeris has joined #ocaml
<ita>
hcarty: not needed *grin*
Oxylin has quit [Client Quit]
smimou has quit ["bli"]
smimou has joined #ocaml
pango has quit [Remote closed the connection]
pango has joined #ocaml
<mqtt>
mrvn, i think i got it! if you're interested, my solution is at http://rafb.net/p/uIds3g89.html. It's not as clean as I wanted, but it should do the job. My structure is now: an unique ID to each node, a 'c' field holding the content to modify, and the mutable succ list. what do you think?
<mqtt>
mrvn, anyway, thank you very much once more for your help. you saved me some more hours of search!
<mrvn>
Yep. that is about how i solved the same problem.
mbishop has quit [Read error: 110 (Connection timed out)]
Smerdyakov has joined #ocaml
pedro_soc has joined #ocaml
ita is now known as ita|afk
ygrek has joined #ocaml
slipstream has joined #ocaml
slipstream-- has quit [Read error: 110 (Connection timed out)]