How to convert a tree using Scrap Your Boilerplate?

I'm new to Haskell, so I'm trying to figure out how to do tree walks.

Here is an example of a company (with a slight change) that I saw in several documents

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 to move the employee from the place where he is in a certain department. This person may be in the department or at ThinkTank.

This seems to be easy to do in SYB as long as you make one type, but I'm not sure how to handle multiple data types.

+7
haskell traversal tree
source share
3 answers

You need to start with the SYB tutorial,

The main features of the bypass:

Play with those who get the point for the API, and you will.

SYB generators are a bit more than a newbie to Haskell.

+5
source share

The cs.uu.nl tutorial seems to have disappeared. For some time I struggled with this, combing the documents, and then wrote this textbook . I hope you find this helpful.

+6
source share

Not too familiar with SYB, so I'll show an example using uniplate . In the example, the employee’s block is only removed from his department or the analytical center, but you can hardly easily figure out how to expand it in order to do what you want.

 > let jack = E (P "Jack" "The Road") (S 7) > import Data.Generics.Uniplate.Data > transformBi (filter (/= PU jack)) $ C [D "Operations" (E (P "Charles" "Seattle") (S 700000)) [PU jack]] C [D "Operations" (E (P "Charles" "Seattle") (S 700000.0)) []] 
0
source share

All Articles