[Haskell-cafe] newbie problems

MR K P SCHUPKE k.schupke at imperial.ac.uk
Sat Jul 3 12:57:04 EDT 2004

The zipper should work on n-ary trees. all the zipper does is
store the tree as (Context,Subtree) so you just need to
adapt that to a Rose-Tree. you could do something like
(and I am thinking out loud here as I havent written zipper code
for rose trees)...

data Context x = Root | Parent x (Context x) [Rose x] [Rose x]
data Rose x = Node x [Rose x]

so at any given point in the tree the context is either Root,
or the Parent (with the value at that node, the parents context, then 
the left siblings and right siblings as lists)

As to the difference between types and values, a type limits
the permitted values. For example

a :: [Int]

a is a list of integers. now

data IntList = Value Int | List [Int]

IntList can be a single int or a list of ints... 

data IntList = Value Int | List [IntList]

Now intlist can be a value or a list of IntLists... we are dealing
with the type of permitted data not the data itself. when we
define a value for example:

a :: IntList
a = Value 3

This must obey the construction rules given in the data type "IntList"
So you see when a data declaration refers to itself it is not a 
"pointer" but an inclusion of the type for example:

a :: IntList
a = List [Value 3,List [Value 2,Value 1],Value 4]

is a valid instance of IntList, but notice that although the 'type'
refers to itself the value is not self-referential. Thats not to
say self referential values are not possible - but lets avoid confusing
the issue with such things.


More information about the Haskell-Cafe mailing list