Commit ba29769c authored by Michael Hanus 's avatar Michael Hanus

Adapt to version3, add Data.Tuple.Extra for the moment

parent bbb7d700
......@@ -14,12 +14,14 @@
PAKCS/KiCS2 distributions.",
"category": [ "Rewriting", "Narrowing" ],
"dependencies": {
"abstract-curry": ">= 3.0.0",
"base" : ">= 2.0.0"
"base" : ">= 3.0.0, < 4.0.0",
"abstract-curry": ">= 3.0.0, < 4.0.0",
"containers" : ">= 3.0.0, < 4.0.0",
"transformers" : ">= 3.0.0, < 4.0.0"
},
"compilerCompatibility": {
"pakcs": ">= 2.0.0",
"kics2": ">= 2.0.0"
"pakcs": ">= 3.0.0, < 4.0.0",
"kics2": ">= 3.0.0, < 4.0.0"
},
"exportedModules": [
"Rewriting.CriticalPairs", "Rewriting.Narrowing", "Rewriting.Strategy",
......
module Data.Tuple.Extra (first, second, (***), (&&&), both) where
--- Apply a function to the first component of a tuple.
first :: (a -> b) -> (a, c) -> (b, c)
first f (x, y) = (f x, y)
--- Apply a function to the second component of a tuple.
second :: (a -> b) -> (c, a) -> (c, b)
second f (x, y) = (x, f y)
--- Apply two functions to the two components of a tuple.
(***) :: (a -> b) -> (c -> d) -> (a, c) -> (b, d)
f *** g = \ (x, y) -> (f x, g y)
--- Apply two functions to a value and returns a tuple of the results.
(&&&) :: (a -> b) -> (a -> c) -> a -> (b, c)
f &&& g = \x -> (f x, g x)
--- Apply a function to both components of a tuple.
both :: (a -> b) -> (a, a) -> (b, b)
both f (x, y) = (f x, f y)
......@@ -63,13 +63,17 @@ showTerm :: (f -> String) -> Term f -> String
showTerm s = showTerm' False
where
showTerm' _ (TermVar v) = showVarIdx v
showTerm' b (TermCons c ts)
= case ts of
[] -> s c
[l, r] -> parensIf b ((showTerm' True l) ++ " " ++ (s c) ++ " "
++ (showTerm' True r))
_ -> (s c) ++ "("
++ (intercalate "," (map (showTerm' False) ts)) ++ ")"
showTerm' b (TermCons c ts) = case ts of
[] -> cstr
[l, r] -> if any isAlphaNum cstr
then prefixString -- no infix notation
else parensIf b (showTerm' True l ++ " " ++ cstr ++ " " ++
showTerm' True r)
_ -> prefixString
where
cstr = s c
prefixString = cstr ++ "("
++ intercalate "," (map (showTerm' False) ts) ++ ")"
--- Transforms a term equation into a string representation.
showTermEq :: (f -> String) -> TermEq f -> String
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment