NCC clean newCell
[fleet.git] / contrib / f0 / Util.lhs
1 \begin{code}
2 module Util where
3 import SBP
4 import List(sort)
5
6 indent []       = []
7 indent ('\n':q) = "\n  "++(indent q)
8 indent (a:b)    = a:(indent b)
9
10 join c []    = ""
11 join c [x]   = x
12 join c (x:y) = x++c++(join c y)
13
14 class FromTree a where
15  fromTree  :: Tree   -> a
16 class FromTrees a where
17  fromTrees :: [Tree] -> a
18 instance FromTree a => FromTree [a] where
19  fromTree (Tree _ c _) = map fromTree c
20 instance FromTree  String where
21   fromTree  (Tree h c _) = h++(concatMap fromTree c)
22 instance FromTrees String where
23   fromTrees ts           = concatMap (fromTree :: Tree -> String) ts
24
25 uniq l = rmdups $ sort l
26  where
27   rmdups []                     = []
28   rmdups [x]                    = [x]
29   rmdups (x:y:rest) | x==y      = rmdups (x:rest)
30                     | otherwise = x:(rmdups (y:rest))
31
32 \end{code}