final pass to update instruction encoding; should now match the spec
[fleet.git] / contrib / f0 / Util.lhs
diff --git a/contrib/f0/Util.lhs b/contrib/f0/Util.lhs
new file mode 100644 (file)
index 0000000..f178fc5
--- /dev/null
@@ -0,0 +1,32 @@
+\begin{code}
+module Util where
+import SBP
+import List(sort)
+
+indent []       = []
+indent ('\n':q) = "\n  "++(indent q)
+indent (a:b)    = a:(indent b)
+
+join c []    = ""
+join c [x]   = x
+join c (x:y) = x++c++(join c y)
+
+class FromTree a where
+ fromTree  :: Tree   -> a
+class FromTrees a where
+ fromTrees :: [Tree] -> a
+instance FromTree a => FromTree [a] where
+ fromTree (Tree _ c _) = map fromTree c
+instance FromTree  String where
+  fromTree  (Tree h c _) = h++(concatMap fromTree c)
+instance FromTrees String where
+  fromTrees ts           = concatMap (fromTree :: Tree -> String) ts
+
+uniq l = rmdups $ sort l
+ where
+  rmdups []                     = []
+  rmdups [x]                    = [x]
+  rmdups (x:y:rest) | x==y      = rmdups (x:rest)
+                    | otherwise = x:(rmdups (y:rest))
+
+\end{code}
\ No newline at end of file