trying to tie the knot
Hal Daume III
hdaume@ISI.EDU
Fri, 12 Apr 2002 10:26:21 -0700 (PDT)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
---559023410-33463914-1018632381=:22333
Content-Type: TEXT/PLAIN; charset=US-ASCII
Hi All,
I thought I was starting to get my head around the whole tying the knot
phenomenon, but when my program produced "*** Exception: <<loop>>" I
figured I was probably missing something :).
Here's what I'm trying to do (I know I could do it without tying the knot,
but that seemed like a reasonable approach and I wanted to get my hands
dirty or feat wet):
I'm reading in a file; that is I have a function String ->
MyDataType. More specifically I'm reading in a Tree, and the tree is
specified in the file with these "Subtree" fields. So you can be reading
along in the tree and then instead of actually seeing a branch or leaf,
you'll see somethign like "[S1]" which means "stick subtree S1 in
here". later in the file (arbitrarily later), you will see something like
"Subtree [S1]" and then following that is that tree.
So what I did was I changed my function to a String -> [(String,Tree)] ->
(Tree, [(String,Tree)] function where the list is a lookup for the
subtrees. I then said:
readTrees s = let (t, st) = readTrees' s st in t
and then the readTrees' basically read the tree in as normal; except when
it gets to something like "[S1]" it does lookup "[S1]" subTrees to get the
subtree and then when it gets to "Subtree [S1]" it reads in the subtree
and then adds it to the subtree list.
Is this not an appropriate use of tying the knot or amd I just doing
something wrong? I've attached my code if you want to read it; It's
marginally more complex that I've written here jsut because of some of the
idiosyncracies in the file format...
- Hal
--
Hal Daume III
"Computer science is no more about computers | hdaume@isi.edu
than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
---559023410-33463914-1018632381=:22333
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="DecisionTree.hs"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.GSO.4.21.0204121026210.22333@moussor.isi.edu>
Content-Description:
Content-Disposition: attachment; filename="DecisionTree.hs"
bW9kdWxlIERlY2lzaW9uVHJlZQ0KICAgIHdoZXJlDQoNCmltcG9ydCBJTw0K
aW1wb3J0IExpc3QNCg0KZGF0Y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