26 lines · 847 B · Text
RawDownload
import Control.Monad.State data Tree a = Empty            | Node (Tree a) a (Tree a) testTree : Tree StringtestTree = Node (Node (Node Empty "Jim" Empty) "Fred"                      (Node Empty "Sheila" Empty)) "Alice"                (Node Empty "Bob" (Node Empty "Eve" Empty)) flatten : Tree a -> List aflatten Empty = []flatten (Node left val right) = flatten left ++ val :: flatten right treeLabelWith : Tree a -> State (Stream labelType) (Tree (labelType, a))treeLabelWith Empty = pure EmptytreeLabelWith (Node left val right)     = do left_labelled <- treeLabelWith left          (this :: rest) <- get          put rest          right_labelled <- treeLabelWith right          pure (Node left_labelled (this, val) right_labelled) treeLabel : Tree a -> Tree (Integer, a)treeLabel tree = evalState (treeLabelWith tree) [1..] 

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t