@@ -1,4 +1,5 @@
1−{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor #-}
1+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2+ TypeSynonymInstances #-}
3module Idris.AbsSyntax where
4module Idris.AbsSyntax where
@@ -56,7 +57,12 @@ data Command = Quit | Help | Eval PTerm
56data Fixity = Infixl { prec :: Int }
57data Fixity = Infixl { prec :: Int }
57 | Infixr { prec :: Int }
58 | Infixr { prec :: Int }
58 | InfixN { prec :: Int }
59 | InfixN { prec :: Int }
59− deriving (Show, Eq)
60+ deriving Eq
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
61data FixDecl = Fix Fixity String
67data FixDecl = Fix Fixity String
62 deriving (Show, Eq)
68 deriving (Show, Eq)
@@ -70,12 +76,12 @@ data PDecl' t = PFix Fixity [String] -- fixity declaration
70 | PTy Name t -- type declaration
76 | PTy Name t -- type declaration
71 | PClause t t -- pattern clause
77 | PClause t t -- pattern clause
72 | PData (PData' t) -- data declaration
78 | PData (PData' t) -- data declaration
73− deriving (Show, Functor)
79+ deriving Functor
75data PData' t = PDatadecl { d_name :: Name,
81data PData' t = PDatadecl { d_name :: Name,
76 d_tcon :: t,
82 d_tcon :: t,
77 d_cons :: [(Name, t)] }
83 d_cons :: [(Name, t)] }
78− deriving (Show, Functor)
84+ deriving Functor
80-- Handy to get a free function for applying PTerm -> PTerm functions
86-- Handy to get a free function for applying PTerm -> PTerm functions
81-- across a program, by deriving Functor
87-- across a program, by deriving Functor
@@ -97,6 +103,21 @@ data PTerm = PQuote Raw
97instance Show PTerm where
103instance Show PTerm where
98 show tm = showImp False tm
104 show tm = showImp False tm
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
112+instance Show PData where
113+ show d = showDImp False d
115+showDImp :: Bool -> PData -> String
116+showDImp impl (PDatadecl n ty cons)
117+ = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
119+ (map (\ (n, t) -> show n ++ " : " ++ showImp impl t) cons)
100showImp :: Bool -> PTerm -> String
121showImp :: Bool -> PTerm -> String
101showImp impl tm = se 10 tm where
122showImp impl tm = se 10 tm where
102 se p (PQuote r) = "![" ++ show r ++ "]"
123 se p (PQuote r) = "![" ++ show r ++ "]"