From f8331e5b4baca2372950f34190ff40d1aa495481 Mon Sep 17 00:00:00 2001 From: krasimir Date: Tue, 28 Oct 2008 12:22:34 +0000 Subject: [PATCH] define Read and Show instances for Expr and Tree --- src/PGF/Expr.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/PGF/Expr.hs b/src/PGF/Expr.hs index 3b8ec01bc..c586aae8c 100644 --- a/src/PGF/Expr.hs +++ b/src/PGF/Expr.hs @@ -38,7 +38,7 @@ data Tree = | Fun CId [Tree] -- ^ function application | Lit Literal -- ^ literal | Meta Int -- ^ meta variable - deriving (Show, Eq, Ord) + deriving (Eq, Ord) -- | An expression represents a potentially unevaluated expression -- in the abstract syntax of the grammar. It can be evaluated with @@ -52,7 +52,7 @@ data Expr = | EVar CId -- ^ variable or function reference | EEq [Equation] -- ^ lambda function defined as a set of equations with pattern matching | EPi CId Expr Expr -- ^ dependent function type - deriving (Eq,Ord,Show) + deriving (Eq,Ord) -- | The equation is used to define lambda function as a sequence -- of equations with pattern matching. The list of 'Expr' represents @@ -72,6 +72,12 @@ readTree s = case [x | (x,cs) <- RP.readP_to_S (pTree False) s, all isSpace cs] showTree :: Tree -> String showTree = PP.render . ppTree 0 +instance Show Tree where + showsPrec i x = showString (PP.render (ppTree i x)) + +instance Read Tree where + readsPrec _ = RP.readP_to_S (pTree False) + -- | parses 'String' as an expression readExpr :: String -> Maybe Expr readExpr s = case [x | (x,cs) <- RP.readP_to_S pExpr s, all isSpace cs] of @@ -82,6 +88,12 @@ readExpr s = case [x | (x,cs) <- RP.readP_to_S pExpr s, all isSpace cs] of showExpr :: Expr -> String showExpr = PP.render . ppExpr 0 +instance Show Expr where + showsPrec i x = showString (PP.render (ppExpr i x)) + +instance Read Expr where + readsPrec _ = RP.readP_to_S pExpr + ----------------------------------------------------- -- Parsing