[Haskell-beginners] growing trees

Jeff Lasslett jeff.lasslett at gmail.com
Sat Aug 4 03:21:40 CEST 2012


Greetings,

For my own edification I have written a few functions for creating a
tree from a list of 'associations'.
An association is defined as

data Assoc = Assoc { label :: String
                   , assocId :: Int
                   , assocPid :: Int
                   }
                   deriving ( Show )

where assocId is an int that uniquely identifies a node, and assocPid
is the id of that node's parent.

The idea is to feed an array of these associations into a function and
get a Data.Tree Assoc out.

So I have code that does the job ...  ... but it's not very good.  I
thought the problem might be
solved with a fold, but that proved difficult due to the Assocs not
being in a suitable insertion order.

Perhaps the routines can be improved such that the array order doesn't matter.

Any advice, or better versions would be appreciated.

thanks,
Jeff

PS: AssocTree.hs should be attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AssocTree.hs
Type: application/octet-stream
Size: 2670 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120804/685324ca/attachment.obj>


More information about the Beginners mailing list