@@ -1,4 +1,5 @@
1−{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor #-}
1+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2+ TypeSynonymInstances #-}
23
34module Idris.AbsSyntax where
45
@@ -56,7 +57,12 @@ data Command = Quit | Help | Eval PTerm
5657data Fixity = Infixl { prec :: Int }
5758 | Infixr { prec :: Int }
5859 | InfixN { prec :: Int }
59− deriving (Show, Eq)
60+ deriving Eq
61+
62+instance Show Fixity where
63+ show (Infixl i) = "infixl " ++ show i
64+ show (Infixr i) = "infixr " ++ show i
65+ show (InfixN i) = "infix " ++ show i
6066
6167data FixDecl = Fix Fixity String
6268 deriving (Show, Eq)
@@ -70,12 +76,12 @@ data PDecl' t = PFix Fixity [String] -- fixity declaration
7076 | PTy Name t -- type declaration
7177 | PClause t t -- pattern clause
7278 | PData (PData' t) -- data declaration
73− deriving (Show, Functor)
79+ deriving Functor
7480
7581data PData' t = PDatadecl { d_name :: Name,
7682 d_tcon :: t,
7783 d_cons :: [(Name, t)] }
78− deriving (Show, Functor)
84+ deriving Functor
7985
8086-- Handy to get a free function for applying PTerm -> PTerm functions
8187-- across a program, by deriving Functor
@@ -97,6 +103,21 @@ data PTerm = PQuote Raw
97103instance Show PTerm where
98104 show tm = showImp False tm
99105
106+instance Show PDecl where
107+ show (PFix f ops) = show f ++ " " ++ showSep ", " ops
108+ show (PTy n ty) = show n ++ " : " ++ show ty
109+ show (PClause l r) = show l ++ " = " ++ show r
110+ show (PData d) = show d
111+
112+instance Show PData where
113+ show d = showDImp False d
114+
115+showDImp :: Bool -> PData -> String
116+showDImp impl (PDatadecl n ty cons)
117+ = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
118+ ++ showSep "\n\t| "
119+ (map (\ (n, t) -> show n ++ " : " ++ showImp impl t) cons)
120+
100121showImp :: Bool -> PTerm -> String
101122showImp impl tm = se 10 tm where
102123 se p (PQuote r) = "![" ++ show r ++ "]"