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
194-- Parsed declarations
196data Fixity = Infixl { prec :: Int }
197 | Infixr { prec :: Int }
198 | InfixN { prec :: Int }
199 | PrefixN { prec :: Int }
202deriving instance Binary Fixity
205instance Show Fixity where
206 show (Infixl i) = "infixl " ++ show i
207 show (Infixr i) = "infixr " ++ show i
208 show (InfixN i) = "infix " ++ show i
209 show (PrefixN i) = "prefix " ++ show i
211data FixDecl = Fix Fixity String
214deriving instance Binary FixDecl
217instance Ord FixDecl where
218 compare (Fix x _) (Fix y _) = compare (prec x) (prec y)
221data Static = Static | Dynamic
224deriving instance Binary Static
227-- Mark bindings with their explicitness, and laziness
228data Plicity = Imp { plazy :: Bool,
230 | Exp { plazy :: Bool,
232 | Constraint { plazy :: Bool,
234 | TacImp { plazy :: Bool,
240deriving instance Binary Plicity
243impl = Imp False Dynamic
244expl = Exp False Dynamic
245constraint = Constraint False Dynamic
246tacimpl = TacImp False Dynamic
248data FnOpt = Inlinable | TotalFn | AssertTotal | TCGen
249 | CExport String -- export, with a C name
250 | Specialise [Name] -- specialise it, freeze these names
253deriving instance Binary FnOpt
258inlinable :: FnOpts -> Bool
259inlinable = elem Inlinable
261data PDecl' t = PFix FC Fixity [String] -- fixity declaration
262 | PTy SyntaxInfo FC FnOpts Name t -- type declaration
263 | PClauses FC FnOpts Name [PClause' t] -- pattern clause
264 | PCAF FC Name t -- top level constant
265 | PData SyntaxInfo FC (PData' t) -- data declaration
266 | PParams FC [(Name, t)] [PDecl' t] -- params block
267 | PNamespace String [PDecl' t] -- new namespace
268 | PRecord SyntaxInfo FC Name t Name t -- record declaration
269 | PClass SyntaxInfo FC
272 [(Name, t)] -- parameters
273 [PDecl' t] -- declarations
274 | PInstance SyntaxInfo FC [t] -- constraints
277 t -- full instance type
278 (Maybe Name) -- explicit name
282 | PDirective (Idris ())
285deriving instance Binary PDecl'
288data PClause' t = PClause FC Name t [t] t [PDecl' t]
289 | PWith FC Name t [t] t [PDecl' t]
290 | PClauseR FC [t] t [PDecl' t]
291 | PWithR FC [t] t [PDecl' t]
294deriving instance Binary PClause'
297data PData' t = PDatadecl { d_name :: Name,
299 d_cons :: [(Name, t, FC)] }
302deriving instance Binary PData'
305-- Handy to get a free function for applying PTerm -> PTerm functions
306-- across a program, by deriving Functor
308type PDecl = PDecl' PTerm
309type PData = PData' PTerm
310type PClause = PClause' PTerm
312-- get all the names declared in a decl
314declared :: PDecl -> [Name]
315declared (PFix _ _ _) = []
316declared (PTy _ _ _ n t) = [n]
317declared (PClauses _ _ n _) = [] -- not a declaration
318declared (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
319 where fstt (a, _, _) = a
320declared (PParams _ _ ds) = concatMap declared ds
321declared (PNamespace _ ds) = concatMap declared ds
322-- declared (PImport _) = []
324defined :: PDecl -> [Name]
325defined (PFix _ _ _) = []
326defined (PTy _ _ _ n t) = []
327defined (PClauses _ _ n _) = [n] -- not a declaration
328defined (PData _ _ (PDatadecl n _ ts)) = n : map fstt ts
329 where fstt (a, _, _) = a
330defined (PParams _ _ ds) = concatMap defined ds
331defined (PNamespace _ ds) = concatMap defined ds
332-- declared (PImport _) = []
334updateN :: [(Name, Name)] -> Name -> Name
335updateN ns n | Just n' <- lookup n ns = n'
338updateNs :: [(Name, Name)] -> PTerm -> PTerm
340updateNs ns t = mapPT updateRef t
341 where updateRef (PRef fc f) = PRef fc (updateN ns f)
344-- updateDNs :: [(Name, Name)] -> PDecl -> PDecl
346-- updateDNs ns (PTy s f n t) | Just n' <- lookup n ns = PTy s f n' t
347-- updateDNs ns (PClauses f n c) | Just n' <- lookup n ns = PClauses f n' (map updateCNs c)
348-- where updateCNs ns (PClause n l ts r ds)
349-- = PClause (updateN ns n) (fmap (updateNs ns) l)
350-- (map (fmap (updateNs ns)) ts)
351-- (fmap (updateNs ns) r)
352-- (map (updateDNs ns) ds)
355-- High level language terms
357data PTerm = PQuote Raw
360 | PLam Name PTerm PTerm
361 | PPi Plicity Name PTerm PTerm
362 | PLet Name PTerm PTerm PTerm
363 | PTyped PTerm PTerm -- term with explicit type
364 | PApp FC PTerm [PArg]
365 | PCase FC PTerm [(PTerm, PTerm)]
371 | PPair FC PTerm PTerm
372 | PDPair FC PTerm PTerm PTerm
373 | PAlternative Bool [PTerm] -- True if only one may work
374 | PHidden PTerm -- irrelevant or hidden pattern
383 | PTactics [PTactic] -- as PProof, but no auto solving
384 | PElabError Err -- error to report on elaboration
385 | PImpossible -- special case for declaring when an LHS can't typecheck
388deriving instance Binary PTerm
391mapPT :: (PTerm -> PTerm) -> PTerm -> PTerm
392mapPT f t = f (mpt t) where
393 mpt (PLam n t s) = PLam n (mapPT f t) (mapPT f s)
394 mpt (PPi p n t s) = PPi p n (mapPT f t) (mapPT f s)
395 mpt (PLet n ty v s) = PLet n (mapPT f ty) (mapPT f v) (mapPT f s)
396 mpt (PApp fc t as) = PApp fc (mapPT f t) (map (fmap (mapPT f)) as)
397 mpt (PCase fc c os) = PCase fc (mapPT f c) (map (pmap (mapPT f)) os)
398 mpt (PEq fc l r) = PEq fc (mapPT f l) (mapPT f r)
399 mpt (PTyped l r) = PTyped (mapPT f l) (mapPT f r)
400 mpt (PPair fc l r) = PPair fc (mapPT f l) (mapPT f r)
401 mpt (PDPair fc l t r) = PDPair fc (mapPT f l) (mapPT f t) (mapPT f r)
402 mpt (PAlternative a as) = PAlternative a (map (mapPT f) as)
403 mpt (PHidden t) = PHidden (mapPT f t)
404 mpt (PDoBlock ds) = PDoBlock (map (fmap (mapPT f)) ds)
405 mpt (PProof ts) = PProof (map (fmap (mapPT f)) ts)
406 mpt (PTactics ts) = PTactics (map (fmap (mapPT f)) ts)
410data PTactic' t = Intro [Name] | Intros | Focus Name
411 | Refine Name [Bool] | Rewrite t | LetTac Name t
412 | Exact t | Compute | Trivial
415 | ProofState | ProofTerm | Undo
416 | Try (PTactic' t) (PTactic' t)
417 | TSeq (PTactic' t) (PTactic' t)
419 deriving (Show, Eq, Functor)
421deriving instance Binary PTactic'
424instance Sized a => Sized (PTactic' a) where
425 size (Intro nms) = 1 + size nms
427 size (Focus nm) = 1 + size nm
428 size (Refine nm bs) = 1 + size nm + length bs
429 size (Rewrite t) = 1 + size t
430 size (LetTac nm t) = 1 + size nm + size t
431 size (Exact t) = 1 + size t
439 size (Try l r) = 1 + size l + size r
440 size (TSeq l r) = 1 + size l + size r
444type PTactic = PTactic' PTerm
446data PDo' t = DoExp FC t
451 deriving (Eq, Functor)
453deriving instance Binary PDo'
456instance Sized a => Sized (PDo' a) where
457 size (DoExp fc t) = 1 + size fc + size t
458 size (DoBind fc nm t) = 1 + size fc + size nm + size t
459 size (DoBindP fc l r) = 1 + size fc + size l + size r
460 size (DoLet fc nm l r) = 1 + size fc + size nm + size l + size r
461 size (DoLetP fc l r) = 1 + size fc + size l + size r
465-- The priority gives a hint as to elaboration order. Best to elaborate
466-- things early which will help give a more concrete type to other
467-- variables, e.g. a before (interpTy a).
469data PArg' t = PImp { priority :: Int,
470 lazyarg :: Bool, pname :: Name, getTm :: t }
471 | PExp { priority :: Int,
472 lazyarg :: Bool, getTm :: t }
473 | PConstraint { priority :: Int,
474 lazyarg :: Bool, getTm :: t }
475 | PTacImplicit { priority :: Int,
476 lazyarg :: Bool, pname :: Name,
479 deriving (Show, Eq, Functor)
481instance Sized a => Sized (PArg' a) where
482 size (PImp p l nm trm) = 1 + size nm + size trm
483 size (PExp p l trm) = 1 + size trm
484 size (PConstraint p l trm) = 1 + size trm
485 size (PTacImplicit p l nm scr trm) = 1 + size nm + size scr + size trm
488deriving instance Binary PArg'
493pconst = PConstraint 0 False
494ptacimp = PTacImplicit 0 True
496type PArg = PArg' PTerm
500data ClassInfo = CI { instanceName :: Name,
501 class_methods :: [(Name, (FnOpts, PTerm))],
502 class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
503 class_params :: [Name],
504 class_instances :: [Name] }
507deriving instance Binary ClassInfo
510data OptInfo = Optimise { collapsible :: Bool,
511 forceable :: [Int], -- argument positions
515deriving instance Binary OptInfo
519data TypeInfo = TI { con_names :: [Name] }
522deriving instance Binary TypeInfo
525-- Syntactic sugar info
527data DSL' t = DSL { dsl_bind :: t,
532 index_first :: Maybe t,
533 index_next :: Maybe t,
534 dsl_lambda :: Maybe t,
537 deriving (Show, Functor)
539deriving instance Binary DSL'
544data SynContext = PatternSyntax | TermSyntax | AnySyntax
547deriving instance Binary SynContext
550data Syntax = Rule [SSymbol] PTerm SynContext
553deriving instance Binary Syntax
556data SSymbol = Keyword Name
563deriving instance Binary SSymbol
566initDSL = DSL (PRef f (UN ">>="))
567 (PRef f (UN "return"))
575 where f = FC "(builtin)" 0
577data SyntaxInfo = Syn { using :: [(Name, PTerm)],
578 syn_params :: [(Name, PTerm)],
579 syn_namespace :: [String],
581 decoration :: Name -> Name,
583 implicitAllowed :: Bool,
587deriving instance Binary SyntaxInfo
590defaultSyntax = Syn [] [] [] [] id False False initDSL
592expandNS :: SyntaxInfo -> Name -> Name
593expandNS syn n@(NS _ _) = n
594expandNS syn n = case syn_namespace syn of
599--- Pretty printing declarations and terms
601instance Show PTerm where
602 show tm = showImp False tm
604instance Pretty PTerm where
605 pretty = prettyImp False
607instance Show PDecl where
608 show d = showDeclImp False d
610instance Show PClause where
611 show c = showCImp True c
613instance Show PData where
614 show d = showDImp False d
616showDeclImp _ (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
617showDeclImp t (PTy _ _ _ n ty) = show n ++ " : " ++ showImp t ty
618showDeclImp _ (PClauses _ _ n c) = showSep "\n" (map show c)
619showDeclImp _ (PData _ _ d) = show d
621showCImp :: Bool -> PClause -> String
622showCImp impl (PClause _ n l ws r w)
623 = showImp impl l ++ showWs ws ++ " = " ++ showImp impl r
624 ++ " where " ++ show w
627 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
628showCImp impl (PWith _ n l ws r w)
629 = showImp impl l ++ showWs ws ++ " with " ++ showImp impl r
630 ++ " { " ++ show w ++ " } "
633 showWs (x : xs) = " | " ++ showImp impl x ++ showWs xs
636showDImp :: Bool -> PData -> String
637showDImp impl (PDatadecl n ty cons)
638 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
640 (map (\ (n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
642getImps :: [PArg] -> [(Name, PTerm)]
644getImps (PImp _ _ n tm : xs) = (n, tm) : getImps xs
645getImps (_ : xs) = getImps xs
647getExps :: [PArg] -> [PTerm]
649getExps (PExp _ _ tm : xs) = tm : getExps xs
650getExps (_ : xs) = getExps xs
652getConsts :: [PArg] -> [PTerm]
654getConsts (PConstraint _ _ tm : xs) = tm : getConsts xs
655getConsts (_ : xs) = getConsts xs
657getAll :: [PArg] -> [PTerm]
660prettyImp :: Bool -> PTerm -> Doc
661prettyImp impl = prettySe 10
663 prettySe p (PQuote r) =
664 if size r > breakingSize then
665 text "![" $$ pretty r <> text "]"
667 text "![" <> pretty r <> text "]"
668 prettySe p (PPatvar fc n) = pretty n
669 prettySe p (PRef fc n) =
675 prettyBasic n@(UN _) = pretty n
676 prettyBasic (MN _ s) = text s
677 prettyBasic (NS n s) = (foldr (<>) empty (intersperse (text ".") (map text $ reverse s))) <> prettyBasic n
678 prettySe p (PLam n ty sc) =
680 if size sc > breakingSize then
681 text "λ" <> pretty n <+> text "=>" $+$ pretty sc
683 text "λ" <> pretty n <+> text "=>" <+> pretty sc
684 prettySe p (PLet n ty v sc) =
686 if size sc > breakingSize then
687 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" $+$
688 nest nestingSize (prettySe 10 sc)
690 text "let" <+> pretty n <+> text "=" <+> prettySe 10 v <+> text "in" <+>
692 prettySe p (PPi (Exp l s) n ty sc)
693 | n `elem` allNamesIn sc || impl =
694 let open = if l then text "|" <> lparen else lparen in
696 if size sc > breakingSize then
697 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
698 st <+> text "->" $+$ prettySe 10 sc
700 open <> pretty n <+> colon <+> prettySe 10 ty <> rparen <+>
701 st <+> text "->" <+> prettySe 10 sc
704 if size sc > breakingSize then
705 prettySe 0 ty <+> st <+> text "->" $+$ prettySe 10 sc
707 prettySe 0 ty <+> st <+> text "->" <+> prettySe 10 sc
711 Static -> text "[static]"
713 prettySe p (PPi (Imp l s) n ty sc)
715 let open = if l then text "|" <> lbrace else lbrace in
717 if size sc > breakingSize then
718 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
719 st <+> text "->" <+> prettySe 10 sc
721 open <> pretty n <+> colon <+> prettySe 10 ty <> rbrace <+>
722 st <+> text "->" <+> prettySe 10 sc
723 | otherwise = prettySe 10 sc
727 Static -> text $ "[static]"
729 prettySe p (PPi (Constraint _ _) n ty sc) =
731 if size sc > breakingSize then
732 prettySe 10 ty <+> text "=>" <+> prettySe 10 sc
734 prettySe 10 ty <+> text "=>" $+$ prettySe 10 sc
735 prettySe p (PPi (TacImp _ _ s) n ty sc) =
737 if size sc > breakingSize then
738 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
739 rbrace <+> text "->" $+$ prettySe 10 sc
741 lbrace <> text "tacimp" <+> pretty n <+> colon <+> prettySe 10 ty <>
742 rbrace <+> text "->" <+> prettySe 10 sc
743 prettySe p (PApp _ (PRef _ f) [])
744 | not impl = pretty f
745 prettySe p (PApp _ (PRef _ op@(UN (f:_))) args)
746 | length (getExps args) == 2 && (not impl) && (not $ isAlpha f) =
747 let [l, r] = getExps args in
749 if size r > breakingSize then
750 prettySe 1 l <+> pretty op $+$ prettySe 0 r
752 prettySe 1 l <+> pretty op <+> prettySe 0 r
753 prettySe p (PApp _ f as) =
754 let args = getExps as in
759 -- foldr (<+>) empty $ map prettyArgS as
762 -- foldr (<+>) empty $ map prettyArgSe args
765 if size r > breakingSize then
766 l $+$ nest nestingSize (prettyArgS r)
771 if size r > breakingSize then
772 l $+$ nest nestingSize (prettyArgSe r)
775 prettySe p (PCase _ scr opts) =
776 text "case" <+> prettySe 10 scr <+> text "of" $+$ nest nestingSize prettyBody
778 prettyBody = foldr ($$) empty $ intersperse (text "|") $ map sc opts
780 sc (l, r) = prettySe 10 l <+> text "=>" <+> prettySe 10 r
781 prettySe p (PHidden tm) = text "." <> prettySe 0 tm
782 prettySe p (PRefl _ _) = text "refl"
783 prettySe p (PResolveTC _) = text "resolvetc"
784 prettySe p (PTrue _) = text "()"
785 prettySe p (PFalse _) = text "_|_"
786 prettySe p (PEq _ l r) =
788 if size r > breakingSize then
789 prettySe 10 l <+> text "=" $$ nest nestingSize (prettySe 10 r)
791 prettySe 10 l <+> text "=" <+> prettySe 10 r
792 prettySe p (PTyped l r) =
793 lparen <> prettySe 10 l <+> colon <+> prettySe 10 r <> rparen
794 prettySe p (PPair _ l r) =
795 if size r > breakingSize then
796 lparen <> prettySe 10 l <> text "," $+$
797 prettySe 10 r <> rparen
799 lparen <> prettySe 10 l <> text "," <+> prettySe 10 r <> rparen
800 prettySe p (PDPair _ l t r) =
801 if size r > breakingSize then
802 lparen <> prettySe 10 l <+> text "**" $+$
803 prettySe 10 r <> rparen
805 lparen <> prettySe 10 l <+> text "**" <+> prettySe 10 r <> rparen
806 prettySe p (PAlternative a as) =
807 lparen <> text "|" <> prettyAs <> text "|" <> rparen
810 foldr (\l -> \r -> l <+> text "," <+> r) empty $ map (prettySe 10) as
811 prettySe p PSet = text "Set"
812 prettySe p (PConstant c) = pretty c
813 -- XXX: add pretty for tactics
814 prettySe p (PProof ts) =
815 text "proof" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
816 prettySe p (PTactics ts) =
817 text "tactics" <+> lbrace $+$ nest nestingSize (text . show $ ts) $+$ rbrace
818 prettySe p (PMetavar n) = text "?" <> pretty n
819 prettySe p (PReturn f) = text "return"
820 prettySe p PImpossible = text "impossible"
821 prettySe p Placeholder = text "_"
822 prettySe p (PDoBlock _) = text "do block pretty not implemented"
823 prettySe p (PElabError s) = pretty s
825 prettySe p _ = text "test"
827 prettyArgS (PImp _ _ n tm) = prettyArgSi (n, tm)
828 prettyArgS (PExp _ _ tm) = prettyArgSe tm
829 prettyArgS (PConstraint _ _ tm) = prettyArgSc tm
830 prettyArgS (PTacImplicit _ _ n _ tm) = prettyArgSti (n, tm)
832 prettyArgSe arg = prettySe 0 arg
833 prettyArgSi (n, val) = lbrace <> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
834 prettyArgSc val = lbrace <> lbrace <> prettySe 10 val <> rbrace <> rbrace
835 prettyArgSti (n, val) = lbrace <> text "auto" <+> pretty n <+> text "=" <+> prettySe 10 val <> rbrace
837 bracket outer inner doc
838 | inner > outer = lparen <> doc <> rparen
841showImp :: Bool -> PTerm -> String
842showImp impl tm = se 10 tm where
843 se p (PQuote r) = "![" ++ show r ++ "]"
844 se p (PPatvar fc n) = show n
845 se p (PRef fc n) = if impl then show n -- ++ "[" ++ show fc ++ "]"
847 where showbasic n@(UN _) = show n
848 showbasic (MN _ s) = s
849 showbasic (NS n s) = showSep "." (reverse s) ++ "." ++ showbasic n
850 se p (PLam n ty sc) = bracket p 2 $ "\\ " ++ show n ++
851 (if impl then " : " ++ se 10 ty else "") ++ " => "
853 se p (PLet n ty v sc) = bracket p 2 $ "let " ++ show n ++ " = " ++ se 10 v ++
855 se p (PPi (Exp l s) n ty sc)
856 | n `elem` allNamesIn sc || impl
858 if l then "|(" else "(" ++
859 show n ++ " : " ++ se 10 ty ++
862 | otherwise = bracket p 2 $ se 0 ty ++ " " ++ st ++ "-> " ++ se 10 sc
864 Static -> "[static] "
866 se p (PPi (Imp l s) n ty sc)
867 | impl = bracket p 2 $ if l then "|{" else "{" ++
868 show n ++ " : " ++ se 10 ty ++
869 "} " ++ st ++ "-> " ++ se 10 sc
870 | otherwise = se 10 sc
872 Static -> "[static] "
874 se p (PPi (Constraint _ _) n ty sc)
875 = bracket p 2 $ se 10 ty ++ " => " ++ se 10 sc
876 se p (PPi (TacImp _ _ s) n ty sc)
877 = bracket p 2 $ "{tacimp " ++ show n ++ " : " ++ se 10 ty ++ "} -> " ++ se 10 sc
878 se p (PApp _ (PRef _ f) [])
880 se p (PApp _ (PRef _ op@(UN (f:_))) args)
881 | length (getExps args) == 2 && not impl && not (isAlpha f)
882 = let [l, r] = getExps args in
883 bracket p 1 $ se 1 l ++ " " ++ show op ++ " " ++ se 0 r
885 = let args = getExps as in
886 bracket p 1 $ se 1 f ++ if impl then concatMap sArg as
887 else concatMap seArg args
888 se p (PCase _ scr opts) = "case " ++ se 10 scr ++ " of " ++ showSep " | " (map sc opts)
889 where sc (l, r) = se 10 l ++ " => " ++ se 10 r
890 se p (PHidden tm) = "." ++ se 0 tm
893 | otherwise = "refl {" ++ se 10 t ++ "}"
894 se p (PResolveTC _) = "resolvetc"
895 se p (PTrue _) = "()"
896 se p (PFalse _) = "_|_"
897 se p (PEq _ l r) = bracket p 2 $ se 10 l ++ " = " ++ se 10 r
898 se p (PTyped l r) = "(" ++ se 10 l ++ " : " ++ se 10 r ++ ")"
899 se p (PPair _ l r) = "(" ++ se 10 l ++ ", " ++ se 10 r ++ ")"
900 se p (PDPair _ l t r) = "(" ++ se 10 l ++ " ** " ++ se 10 r ++ ")"
901 se p (PAlternative a as) = "(|" ++ showSep " , " (map (se 10) as) ++ "|)"
903 se p (PConstant c) = show c
904 se p (PProof ts) = "proof { " ++ show ts ++ "}"
905 se p (PTactics ts) = "tactics { " ++ show ts ++ "}"
906 se p (PMetavar n) = "?" ++ show n
907 se p (PReturn f) = "return"
908 se p PImpossible = "impossible"
909 se p Placeholder = "_"
910 se p (PDoBlock _) = "do block show not implemented"
911 se p (PElabError s) = show s
912-- se p x = "Not implemented"
914 sArg (PImp _ _ n tm) = siArg (n, tm)
915 sArg (PExp _ _ tm) = seArg tm
916 sArg (PConstraint _ _ tm) = scArg tm
917 sArg (PTacImplicit _ _ n _ tm) = stiArg (n, tm)
919 seArg arg = " " ++ se 0 arg
920 siArg (n, val) = " {" ++ show n ++ " = " ++ se 10 val ++ "}"
921 scArg val = " {{" ++ se 10 val ++ "}}"
922 stiArg (n, val) = " {auto " ++ show n ++ " = " ++ se 10 val ++ "}"
924 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
930 | PLam Name PTerm PTerm
931 | PPi Plicity Name PTerm PTerm
932 | PLet Name PTerm PTerm PTerm
933 | PTyped PTerm PTerm -- term with explicit type
934 | PApp FC PTerm [PArg]
935 | PCase FC PTerm [(PTerm, PTerm)]
941 | PPair FC PTerm PTerm
942 | PDPair FC PTerm PTerm PTerm
943 | PAlternative [PTerm]
944 | PHidden PTerm -- irrelevant or hidden pattern
953 | PTactics [PTactic] -- as PProof, but no auto solving
954 | PElabError Err -- error to report on elaboration
955 | PImpossible -- special case for declaring when an LHS can't typecheck
958instance Sized PTerm where
959 size (PQuote rawTerm) = size rawTerm
960 size (PRef fc name) = size name
961 size (PLam name ty bdy) = 1 + size ty + size bdy
962 size (PPi plicity name ty bdy) = 1 + size ty + size bdy
963 size (PLet name ty def bdy) = 1 + size ty + size def + size bdy
964 size (PTyped trm ty) = 1 + size trm + size ty
965 size (PApp fc name args) = 1 + size args
966 size (PCase fc trm bdy) = 1 + size trm + size bdy
969 size (PRefl fc _) = 1
970 size (PResolveTC fc) = 1
971 size (PEq fc left right) = 1 + size left + size right
972 size (PPair fc left right) = 1 + size left + size right
973 size (PDPair fs left ty right) = 1 + size left + size ty + size right
974 size (PAlternative a alts) = 1 + size alts
975 size (PHidden hidden) = size hidden
977 size (PConstant const) = 1 + size const
979 size (PDoBlock dos) = 1 + size dos
980 size (PIdiom fc term) = 1 + size term
981 size (PReturn fc) = 1
982 size (PMetavar name) = 1
983 size (PProof tactics) = size tactics
984 size (PElabError err) = size err
987allNamesIn :: PTerm -> [Name]
988allNamesIn tm = nub $ ni [] tm
991 | not (n `elem` env) = [n]
992 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
993 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
994 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
995 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
996 ni env (PHidden tm) = ni env tm
997 ni env (PEq _ l r) = ni env l ++ ni env r
998 ni env (PTyped l r) = ni env l ++ ni env r
999 ni env (PPair _ l r) = ni env l ++ ni env r
1000 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1001 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1002 ni env (PAlternative a ls) = concatMap (ni env) ls
1005namesIn :: [(Name, PTerm)] -> IState -> PTerm -> [Name]
1006namesIn uvars ist tm = nub $ ni [] tm
1009 | not (n `elem` env)
1010 = case lookupTy Nothing n (tt_ctxt ist) of
1012 _ -> if n `elem` (map fst uvars) then [n] else []
1013 ni env (PApp _ f as) = ni env f ++ concatMap (ni env) (map getTm as)
1014 ni env (PCase _ c os) = ni env c ++ concatMap (ni env) (map snd os)
1015 ni env (PLam n ty sc) = ni env ty ++ ni (n:env) sc
1016 ni env (PPi _ n ty sc) = ni env ty ++ ni (n:env) sc
1017 ni env (PEq _ l r) = ni env l ++ ni env r
1018 ni env (PTyped l r) = ni env l ++ ni env r
1019 ni env (PPair _ l r) = ni env l ++ ni env r
1020 ni env (PDPair _ (PRef _ n) t r) = ni env t ++ ni (n:env) r
1021 ni env (PDPair _ l t r) = ni env l ++ ni env t ++ ni env r
1022 ni env (PAlternative a as) = concatMap (ni env) as
1023 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