1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, DeriveFunctor,
2 TypeSynonymInstances, PatternGuards #-}
4module Idris.AbsSyntaxTree where
8import Core.Elaborate hiding (Tactic(..))
15import System.Console.Haskeline
17import Control.Monad.State
25data IOption = IOption { opt_logLevel :: Int,
27 opt_typeintype :: Bool,
30 opt_errContext :: Bool,
33 opt_ibcsubdir :: FilePath,
34 opt_importdirs :: [FilePath],
35 opt_cmdline :: [Opt] -- remember whole command line
39defaultOpts = IOption 0 False False True False False True True "" [] []
41-- TODO: Add 'module data' to IState, which can be saved out and reloaded quickly (i.e
42-- without typechecking).
43-- This will include all the functions and data declarations, plus fixity declarations
48 idris_constraints :: [(UConstraint, FC)],
49 idris_infixes :: [FixDecl],
50 idris_implicits :: Ctxt [PArg],
51 idris_statics :: Ctxt [Bool],
52 idris_classes :: Ctxt ClassInfo,
53 idris_dsls :: Ctxt DSL,
54 idris_optimisation :: Ctxt OptInfo,
55 idris_datatypes :: Ctxt TypeInfo,
56 idris_patdefs :: Ctxt [([Name], Term, Term)], -- not exported
57 idris_flags :: Ctxt [FnOpt],
58 idris_callgraph :: Ctxt CGInfo, -- name, args used in each pos
59 idris_calledgraph :: Ctxt [Name],
60 idris_totcheck :: [(FC, Name)],
62 idris_options :: IOption,
64 idris_metavars :: [Name],
65 syntax_rules :: [Syntax],
66 syntax_keywords :: [String],
67 imported :: [FilePath],
68 idris_scprims :: [(Name, (Int, PrimFn))],
69 idris_objs :: [FilePath],
70 idris_libs :: [String],
71 idris_hdrs :: [String],
72 proof_list :: [(Name, [String])],
74 lastParse :: Maybe Name,
75 indent_stack :: [Int],
76 brace_stack :: [Maybe Int],
77 hide_list :: [(Name, Maybe Accessibility)],
78 default_access :: Accessibility,
79 ibc_write :: [IBCWrite],
80 compiled_so :: Maybe String
83data CGInfo = CGInfo { argsdef :: [Name],
84 calls :: [(Name, [[Name]])],
89deriving instance Binary CGInfo
92primDefs = [UN "unsafePerformIO", UN "mkLazyForeign", UN "mkForeign", UN "FalseElim"]
94-- information that needs writing for the current module's .ibc file
95data IBCWrite = IBCFix FixDecl
99 | IBCInstance Bool Name Name
109 | IBCAccess Name Accessibility
110 | IBCTotal Name Totality
111 | IBCFlags Name [FnOpt]
113 | IBCDef Name -- i.e. main context
116idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
117 emptyContext emptyContext emptyContext emptyContext
118 emptyContext emptyContext emptyContext
119 [] "" defaultOpts 6 [] [] [] [] [] [] [] []
120 [] Nothing Nothing [] [] [] Hidden [] Nothing
122-- The monad for the main REPL - reading and processing files and updating
123-- global state (hence the IO inner monad).
124type Idris = StateT IState (InputT IO)
126-- Commands in the REPL
128data Target = ViaC | ViaJava
137 | Compile Target String
162data Opt = Filename String
193-- Parsed declarations
195data Fixity = Infixl { prec :: Int }
196 | Infixr { prec :: Int }
197 | InfixN { prec :: Int }
198 | PrefixN { prec :: Int }
201deriving instance Binary Fixity
204instance Show Fixity where
205 show (Infixl i) = "infixl " ++ show i
206 show (Infixr i) = "infixr " ++ show i
207 show (InfixN i) = "infix " ++ show i
208 show (PrefixN i) = "prefix " ++ show i
210data FixDecl = Fix Fixity String
213deriving instance Binary FixDecl
216instance Ord FixDecl where
217 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
220data Static = Static | Dynamic
223deriving instance Binary Static
226-- Mark bindings with their explicitness, and laziness
227data Plicity = Imp { plazy :: Bool,
229 | Exp { plazy :: Bool,
231 | Constraint { plazy :: Bool,
233 | TacImp { plazy :: Bool,
239deriving instance Binary Plicity
242impl = Imp False Dynamic
243expl = Exp False Dynamic
244constraint = Constraint False Dynamic
245tacimpl = TacImp False Dynamic
247data FnOpt = Inlinable | TotalFn | AssertTotal | TCGen
248 | CExport String -- export, with a C name
249 | Specialise [Name] -- specialise it, freeze these names
252deriving instance Binary FnOpt
257inlinable :: FnOpts -> Bool
258inlinable = elem Inlinable
260data PDecl' t = PFix FC Fixity [String] -- fixity declaration
261 | PTy SyntaxInfo FC FnOpts Name t -- type declaration
262 | PClauses FC FnOpts Name [PClause' t] -- pattern clause
263 | PCAF FC Name t -- top level constant
264 | PData SyntaxInfo FC (PData' t) -- data declaration
265 | PParams FC [(Name, t)] [PDecl' t] -- params block
266 | PNamespace String [PDecl' t] -- new namespace
267 | PRecord SyntaxInfo FC Name t Name t -- record declaration
268 | PClass SyntaxInfo FC
271 [(Name, t)] -- parameters
272 [PDecl' t] -- declarations
273 | PInstance SyntaxInfo FC [t] -- constraints
276 t -- full instance type
277 (Maybe Name) -- explicit name
281 | PDirective (Idris ())
284deriving instance Binary PDecl'
287data PClause' t = PClause FC Name t [t] t [PDecl' t]
288 | PWith FC Name t [t] t [PDecl' t]
289 | PClauseR FC [t] t [PDecl' t]
290 | PWithR FC [t] t [PDecl' t]
293deriving instance Binary PClause'
296data PData' t = PDatadecl { d_name :: Name,
298 d_cons :: [(Name, t, FC)] }
301deriving instance Binary PData'
304-- Handy to get a free function for applying PTerm -> PTerm functions
305-- across a program, by deriving Functor
307type PDecl = PDecl' PTerm
308type PData = PData' PTerm
309type PClause = PClause' PTerm
311-- get all the names declared in a decl
313declared :: PDecl -> [Name]
314declared (PFix _ _ _) = []
315declared (PTy _ _ _ n t) = [n]
316declared (PClauses _ _ n _) = [] -- not a declaration
317declared (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
318 where fstt (a, _, _) = a
319declared (PParams _ _ ds) = concatMap declared ds
320declared (PNamespace _ ds) = concatMap declared ds
321-- declared (PImport _) = []
323defined :: PDecl -> [Name]
324defined (PFix _ _ _) = []
325defined (PTy _ _ _ n t) = []
326defined (PClauses _ _ n _) = [n] -- not a declaration
327defined (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
328 where fstt (a, _, _) = a
329defined (PParams _ _ ds) = concatMap defined ds
330defined (PNamespace _ ds) = concatMap defined ds
331-- declared (PImport _) = []
333updateN :: [(Name, Name)] -> Name -> Name
334updateN ns n | Just n' <- lookup n ns = n'
337updateNs :: [(Name, Name)] -> PTerm -> PTerm
339updateNs ns t = mapPT updateRef t
340 where updateRef (PRef fc f) = PRef fc (updateN ns f)
343-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
345-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
346-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
347-- where updateCNs ns (PClause n l ts r ds)
348-- = PClause (updateN ns n) (fmap (updateNs ns) l)
349-- (map (fmap (updateNs ns)) ts)
350-- (fmap (updateNs ns) r)
351-- (map (updateDNs ns) ds)
354-- High level language terms
356data PTerm = PQuote Raw
359 | PLam Name PTerm PTerm
360 | PPi Plicity Name PTerm PTerm
361 | PLet Name PTerm PTerm PTerm
362 | PTyped PTerm PTerm -- term with explicit type
363 | PApp FC PTerm [PArg]
364 | PCase FC PTerm [(PTerm, PTerm)]
370 | PPair FC PTerm PTerm
371 | PDPair FC PTerm PTerm PTerm
372 | PAlternative Bool [PTerm] -- True if only one may work
373 | PHidden PTerm -- irrelevant or hidden pattern
382 | PTactics [PTactic] -- as PProof, but no auto solving
383 | PElabError Err -- error to report on elaboration
384 | PImpossible -- special case for declaring when an LHS can't typecheck
387deriving instance Binary PTerm
390mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
391mapPT f t = f (mpt t) where
392 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
393 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
394 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
395 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
396 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
397 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
398 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
399 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
400 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
401 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
402 mpt (PHidden t) = PHidden (mapPT f t)
403 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
404 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
405 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
409data PTactic' t = Intro [Name] | Intros | Focus Name
410 | Refine Name [Bool] | Rewrite t | LetTac Name t
411 | Exact t | Compute | Trivial
414 | ProofState | ProofTerm | Undo
415 | Try (PTactic' t) (PTactic' t)
416 | TSeq (PTactic' t) (PTactic' t)
418 deriving (Show, Eq, Functor)
420deriving instance Binary PTactic'
423instance Sized a => Sized (PTactic' a) where
424 size (Intro nms) = 1 + size nms
426 size (Focus nm) = 1 + size nm
427 size (Refine nm bs) = 1 + size nm + length bs
428 size (Rewrite t) = 1 + size t
429 size (LetTac nm t) = 1 + size nm + size t
430 size (Exact t) = 1 + size t
438 size (Try l r) = 1 + size l + size r
439 size (TSeq l r) = 1 + size l + size r
443type PTactic = PTactic' PTerm
445data PDo' t = DoExp FC t
450 deriving (Eq, Functor)
452deriving instance Binary PDo'
455instance Sized a => Sized (PDo' a) where
456 size (DoExp fc t) = 1 + size fc + size t
457 size (DoBind fc nm t) = 1 + size fc + size nm + size t
458 size (DoBindP fc l r) = 1 + size fc + size l + size r
459 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
460 size (DoLetP fc l r) = 1 + size fc + size l + size r
464-- The priority gives a hint as to elaboration order. Best to elaborate
465-- things early which will help give a more concrete type to other
466-- variables, e.g. a before (interpTy a).
468data PArg' t = PImp { priority :: Int,
469 lazyarg :: Bool, pname :: Name, getTm :: t }
470 | PExp { priority :: Int,
471 lazyarg :: Bool, getTm :: t }
472 | PConstraint { priority :: Int,
473 lazyarg :: Bool, getTm :: t }
474 | PTacImplicit { priority :: Int,
475 lazyarg :: Bool, pname :: Name,
478 deriving (Show, Eq, Functor)
480instance Sized a => Sized (PArg' a) where
481 size (PImp p l nm trm) = 1 + size nm + size trm
482 size (PExp p l trm) = 1 + size trm
483 size (PConstraint p l trm) = 1 + size trm
484 size (PTacImplicit p l nm scr trm) = 1 + size nm + size scr + size trm
487deriving instance Binary PArg'
492pconst = PConstraint 0 False
493ptacimp = PTacImplicit 0 True
495type PArg = PArg' PTerm
499data ClassInfo = CI { instanceName :: Name,
500 class_methods :: [(Name, (FnOpts, PTerm))],
501 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
502 class_params :: [Name],
503 class_instances :: [Name] }
506deriving instance Binary ClassInfo
509data OptInfo = Optimise { collapsible :: Bool,
510 forceable :: [Int], -- argument positions
514deriving instance Binary OptInfo
518data TypeInfo = TI { con_names :: [Name] }
521deriving instance Binary TypeInfo
524-- Syntactic sugar info
526data DSL' t = DSL { dsl_bind :: t,
531 index_first :: Maybe t,
532 index_next :: Maybe t,
533 dsl_lambda :: Maybe t,
536 deriving (Show, Functor)
538deriving instance Binary DSL'
543data SynContext = PatternSyntax | TermSyntax | AnySyntax
546deriving instance Binary SynContext
549data Syntax = Rule [SSymbol] PTerm SynContext
552deriving instance Binary Syntax
555data SSymbol = Keyword Name
562deriving instance Binary SSymbol
565initDSL = DSL (PRef f (UN ">>="))
566 (PRef f (UN "return"))
574 where f = FC "(builtin)" 0
576data SyntaxInfo = Syn { using :: [(Name, PTerm)],
577 syn_params :: [(Name, PTerm)],
578 syn_namespace :: [String],
580 decoration :: Name -> Name,
582 implicitAllowed :: Bool,
586deriving instance Binary SyntaxInfo
589defaultSyntax = Syn [] [] [] [] id False False initDSL
591expandNS :: SyntaxInfo -> Name -> Name
592expandNS syn n@(NS _ _) = n
593expandNS syn n = case syn_namespace syn of
598--- Pretty printing declarations and terms
600instance Show PTerm where
601 show tm = showImp False tm
603instance Pretty PTerm where
604 pretty = prettyImp False
606instance Show PDecl where
607 show d = showDeclImp False d
609instance Show PClause where
610 show c = showCImp True c
612instance Show PData where
613 show d = showDImp False d
615showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
616showDeclImp t (PTy _ _ _ n ty) = show n ++ " : " ++ showImp t ty
617showDeclImp _ (PClauses _ _ n c) = showSep "\n" (map show c)
618showDeclImp _ (PData _ _ d) = show d
620showCImp :: Bool -> PClause -> String
621showCImp impl (PClause _ n l ws r w)
622 = showImp impl l ++ showWs ws ++ " = " ++ showImp impl r
623 ++ " where " ++ show w
626 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
627showCImp impl (PWith _ n l ws r w)
628 = showImp impl l ++ showWs ws ++ " with " ++ showImp impl r
629 ++ " { " ++ show w ++ " } "
632 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
635showDImp :: Bool -> PData -> String
636showDImp impl (PDatadecl n ty cons)
637 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
639 (map (\ (n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
641getImps :: [PArg] -> [(Name, PTerm)]
643getImps (PImp _ _ n tm : xs) = (n, tm) : getImps xs
644getImps (_ : xs) = getImps xs
646getExps :: [PArg] -> [PTerm]
648getExps (PExp _ _ tm : xs) = tm : getExps xs
649getExps (_ : xs) = getExps xs
651getConsts :: [PArg] -> [PTerm]
653getConsts (PConstraint _ _ tm : xs) = tm : getConsts xs
654getConsts (_ : xs) = getConsts xs
656getAll :: [PArg] -> [PTerm]
659prettyImp :: Bool -> PTerm -> Doc
660prettyImp impl = prettySe 10
662 prettySe p (PQuote r) =
663 if size r > breakingSize then
664 text "![" $$ pretty r <> text "]"
666 text "![" <> pretty r <> text "]"
667 prettySe p (PPatvar fc n) = pretty n
668 prettySe p (PRef fc n) =
674 prettyBasic n@(UN _) = pretty n
675 prettyBasic (MN _ s) = text s
676 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
677 prettySe p (PLam n ty sc) =
679 if size sc > breakingSize then
680 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
682 text "λ" <> pretty n <+> text "=>" <+> pretty sc
683 prettySe p (PLet n ty v sc) =
685 if size sc > breakingSize then
686 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
687 nest nestingSize (prettySe 10 sc)
689 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
691 prettySe p (PPi (Exp l s) n ty sc)
692 | n `elem` allNamesIn sc || impl =
693 let open = if l then text "|" <> lparen else lparen in
695 if size sc > breakingSize then
696 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
697 st <+> text "->" $+$ prettySe 10 sc
699 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
700 st <+> text "->" <+> prettySe 10 sc
703 if size sc > breakingSize then
704 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
706 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
710 Static -> text "[static]"
712 prettySe p (PPi (Imp l s) n ty sc)
714 let open = if l then text "|" <> lbrace else lbrace in
716 if size sc > breakingSize then
717 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
718 st <+> text "->" <+> prettySe 10 sc
720 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
721 st <+> text "->" <+> prettySe 10 sc
722 | otherwise = prettySe 10 sc
726 Static -> text $ "[static]"
728 prettySe p (PPi (Constraint _ _) n ty sc) =
730 if size sc > breakingSize then
731 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
733 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
734 prettySe p (PPi (TacImp _ _ s) n ty sc) =
736 if size sc > breakingSize then
737 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
738 rbrace <+> text "->" $+$ prettySe 10 sc
740 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
741 rbrace <+> text "->" <+> prettySe 10 sc
742 prettySe p (PApp _ (PRef _ f) [])
743 | not impl = pretty f
744 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
745 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
746 let [l, r] = getExps args in
748 if size r > breakingSize then
749 prettySe 1 l <+> pretty op $+$ prettySe 0 r
751 prettySe 1 l <+> pretty op <+> prettySe 0 r
752 prettySe p (PApp _ f as) =
753 let args = getExps as in
758 -- foldr (<+>) empty $ map prettyArgS as
761 -- foldr (<+>) empty $ map prettyArgSe args
764 if size r > breakingSize then
765 l $+$ nest nestingSize (prettyArgS r)
770 if size r > breakingSize then
771 l $+$ nest nestingSize (prettyArgSe r)
774 prettySe p (PCase _ scr opts) =
775 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
777 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
779 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
780 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
781 prettySe p (PRefl _ _) = text "refl"
782 prettySe p (PResolveTC _) = text "resolvetc"
783 prettySe p (PTrue _) = text "()"
784 prettySe p (PFalse _) = text "_|_"
785 prettySe p (PEq _ l r) =
787 if size r > breakingSize then
788 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
790 prettySe 10 l <+> text "=" <+> prettySe 10 r
791 prettySe p (PTyped l r) =
792 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
793 prettySe p (PPair _ l r) =
794 if size r > breakingSize then
795 lparen <> prettySe 10 l <> text "," $+$
796 prettySe 10 r <> rparen
798 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
799 prettySe p (PDPair _ l t r) =
800 if size r > breakingSize then
801 lparen <> prettySe 10 l <+> text "**" $+$
802 prettySe 10 r <> rparen
804 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
805 prettySe p (PAlternative a as) =
806 lparen <> text "|" <> prettyAs <> text "|" <> rparen
809 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
810 prettySe p PSet = text "Set"
811 prettySe p (PConstant c) = pretty c
812 -- XXX: add pretty for tactics
813 prettySe p (PProof ts) =
814 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
815 prettySe p (PTactics ts) =
816 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
817 prettySe p (PMetavar n) = text "?" <> pretty n
818 prettySe p (PReturn f) = text "return"
819 prettySe p PImpossible = text "impossible"
820 prettySe p Placeholder = text "_"
821 prettySe p (PDoBlock _) = text "do block pretty not implemented"
822 prettySe p (PElabError s) = pretty s
824 prettySe p _ = text "test"
826 prettyArgS (PImp _ _ n tm) = prettyArgSi (n, tm)
827 prettyArgS (PExp _ _ tm) = prettyArgSe tm
828 prettyArgS (PConstraint _ _ tm) = prettyArgSc tm
829 prettyArgS (PTacImplicit _ _ n _ tm) = prettyArgSti (n, tm)
831 prettyArgSe arg = prettySe 0 arg
832 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
833 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
834 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
836 bracket outer inner doc
837 | inner > outer = lparen <> doc <> rparen
840showImp :: Bool -> PTerm -> String
841showImp impl tm = se 10 tm where
842 se p (PQuote r) = "![" ++ show r ++ "]"
843 se p (PPatvar fc n) = show n
844 se p (PRef fc n) = if impl then show n -- ++ "[" ++ show fc ++ "]"
846 where showbasic n@(UN _) = show n
847 showbasic (MN _ s) = s
848 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
849 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++
850 (if impl then " : " ++ se 10 ty else "") ++ " => "
852 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
854 se p (PPi (Exp l s) n ty sc)
855 | n `elem` allNamesIn sc || impl
857 if l then "|(" else "(" ++
858 show n ++ " : " ++ se 10 ty ++
861 | otherwise = bracket p 2 $ se 0 ty ++ " " ++ st ++ "-> " ++ se 10 sc
863 Static -> "[static] "
865 se p (PPi (Imp l s) n ty sc)
866 | impl = bracket p 2 $ if l then "|{" else "{" ++
867 show n ++ " : " ++ se 10 ty ++
868 "} " ++ st ++ "-> " ++ se 10 sc
869 | otherwise = se 10 sc
871 Static -> "[static] "
873 se p (PPi (Constraint _ _) n ty sc)
874 = bracket p 2 $ se 10 ty ++ " => " ++ se 10 sc
875 se p (PPi (TacImp _ _ s) n ty sc)
876 = bracket p 2 $ "{tacimp " ++ show n ++ " : " ++ se 10 ty ++ "} -> " ++ se 10 sc
877 se p (PApp _ (PRef _ f) [])
879 se p (PApp _ (PRef _ op@(UN (f:_))) args)
880 | length (getExps args) == 2 && not impl && not (isAlpha f)
881 = let [l, r] = getExps args in
882 bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 0 r
884 = let args = getExps as in
885 bracket p 1 $ se 1 f ++ if impl then concatMap sArg as
886 else concatMap seArg args
887 se p (PCase _ scr opts) = "case " ++ se 10 scr ++ " of " ++ showSep " | " (map sc opts)
888 where sc (l, r) = se 10 l ++ " => " ++ se 10 r
889 se p (PHidden tm) = "." ++ se 0 tm
892 | otherwise = "refl {" ++ se 10 t ++ "}"
893 se p (PResolveTC _) = "resolvetc"
894 se p (PTrue _) = "()"
895 se p (PFalse _) = "_|_"
896 se p (PEq _ l r) = bracket p 2 $ se 10 l ++ " = " ++ se 10 r
897 se p (PTyped l r) = "(" ++ se 10 l ++ " : " ++ se 10 r ++ ")"
898 se p (PPair _ l r) = "(" ++ se 10 l ++ ", " ++ se 10 r ++ ")"
899 se p (PDPair _ l t r) = "(" ++ se 10 l ++ " ** " ++ se 10 r ++ ")"
900 se p (PAlternative a as) = "(|" ++ showSep " , " (map (se 10) as) ++ "|)"
902 se p (PConstant c) = show c
903 se p (PProof ts) = "proof { " ++ show ts ++ "}"
904 se p (PTactics ts) = "tactics { " ++ show ts ++ "}"
905 se p (PMetavar n) = "?" ++ show n
906 se p (PReturn f) = "return"
907 se p PImpossible = "impossible"
908 se p Placeholder = "_"
909 se p (PDoBlock _) = "do block show not implemented"
910 se p (PElabError s) = show s
911-- se p x = "Not implemented"
913 sArg (PImp _ _ n tm) = siArg (n, tm)
914 sArg (PExp _ _ tm) = seArg tm
915 sArg (PConstraint _ _ tm) = scArg tm
916 sArg (PTacImplicit _ _ n _ tm) = stiArg (n, tm)
918 seArg arg = " " ++ se 0 arg
919 siArg (n, val) = " {" ++ show n ++ " = " ++ se 10 val ++ "}"
920 scArg val = " {{" ++ se 10 val ++ "}}"
921 stiArg (n, val) = " {auto " ++ show n ++ " = " ++ se 10 val ++ "}"
923 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
929 | PLam Name PTerm PTerm
930 | PPi Plicity Name PTerm PTerm
931 | PLet Name PTerm PTerm PTerm
932 | PTyped PTerm PTerm -- term with explicit type
933 | PApp FC PTerm [PArg]
934 | PCase FC PTerm [(PTerm, PTerm)]
940 | PPair FC PTerm PTerm
941 | PDPair FC PTerm PTerm PTerm
942 | PAlternative [PTerm]
943 | PHidden PTerm -- irrelevant or hidden pattern
952 | PTactics [PTactic] -- as PProof, but no auto solving
953 | PElabError Err -- error to report on elaboration
954 | PImpossible -- special case for declaring when an LHS can't typecheck
957instance Sized PTerm where
958 size (PQuote rawTerm) = size rawTerm
959 size (PRef fc name) = size name
960 size (PLam name ty bdy) = 1 + size ty + size bdy
961 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
962 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
963 size (PTyped trm ty) = 1 + size trm + size ty
964 size (PApp fc name args) = 1 + size args
965 size (PCase fc trm bdy) = 1 + size trm + size bdy
968 size (PRefl fc _) = 1
969 size (PResolveTC fc) = 1
970 size (PEq fc left right) = 1 + size left + size right
971 size (PPair fc left right) = 1 + size left + size right
972 size (PDPair fs left ty right) = 1 + size left + size ty + size right
973 size (PAlternative a alts) = 1 + size alts
974 size (PHidden hidden) = size hidden
976 size (PConstant const) = 1 + size const
978 size (PDoBlock dos) = 1 + size dos
979 size (PIdiom fc term) = 1 + size term
980 size (PReturn fc) = 1
981 size (PMetavar name) = 1
982 size (PProof tactics) = size tactics
983 size (PElabError err) = size err
986allNamesIn :: PTerm -> [Name]
987allNamesIn tm = nub $ ni [] tm
990 | not (n `elem` env) = [n]
991 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
992 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
993 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
994 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
995 ni env (PHidden tm) = ni env tm
996 ni env (PEq _ l r) = ni env l ++ ni env r
997 ni env (PTyped l r) = ni env l ++ ni env r
998 ni env (PPair _ l r) = ni env l ++ ni env r
999 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1000 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1001 ni env (PAlternative a ls) = concatMap (ni env) ls
1004namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1005namesIn uvars ist tm = nub $ ni [] tm
1008 | not (n `elem` env)
1009 = case lookupTy Nothing n (tt_ctxt ist) of
1011 _ -> if n `elem` (map fst uvars) then [n] else []
1012 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1013 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1014 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1015 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1016 ni env (PEq _ l r) = ni env l ++ ni env r
1017 ni env (PTyped l r) = ni env l ++ ni env r
1018 ni env (PPair _ l r) = ni env l ++ ni env r
1019 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1020 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1021 ni env (PAlternative a as) = concatMap (ni env) as
1022 ni env (PHidden tm) = ni env tm
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list