Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do transform a tree using Scrap Your Boilerplate?

I am new to Haskell, so I am trying to figure out how to do tree traversals.

Here is the Company example (with a slight change) that I have seen in several papers

data Company  = C [Dept]               deriving (Eq, Show, Typeable, Data)
data Dept     = D Name Manager [Unit]  deriving (Eq, Show, Typeable, Data)
data ThinkTank= TK Name [Unit]         deriving (Eq, Show, Typeable, Data)
data Unit     = PU Employee | DU Dept  deriving (Eq, Show, Typeable, Data)
data Employee = E Person Salary        deriving (Eq, Show, Typeable, Data)
data Person   = P Name Address         deriving (Eq, Show, Typeable, Data)
data Salary   = S Float                deriving (Eq, Show, Typeable, Data)
type Manager  = Employee
type Name     = String
type Address  = String

What I would like to do is move a Employee from where he is to a particular department. This person could be in a Department or a ThinkTank.

It seems easy to do things in SYB as long as you are doing one type, but I am not sure how to deal with multiple data types.

like image 735
Chris Avatar asked Mar 06 '10 04:03

Chris


1 Answers

The tutorial at cs.uu.nl seems to have disappeared. I struggled for a while with this, combing through papers, then wrote this tutorial. Hope you find it useful.

like image 168
user1989402 Avatar answered Sep 22 '22 20:09

user1989402