on master help sign in
Source file stylings & Haddock.

+ Harmonised various formatting of data structures. + Ammended documentation for various functions and data structures.

commit1019ce5aa4697b5ca5afd7639a183f9102653dcc authorJan de Muijnck-Hughes <jfdm@st-andrews.ac.uk> dateMon 16 May 2016, 16:43 (10 years ago) parentf8e66f9
27 files changed+1064−941
src/Idris/ASTUtils.hs+14−19 src/Idris/AbsSyntax.hs+40−37 src/Idris/AbsSyntaxTree.hs+496−412 src/Idris/CaseSplit.hs+11−11 src/Idris/Chaser.hs+16−15 src/Idris/Coverage.hs+22−25 src/Idris/DataOpts.hs+1−1 src/Idris/Elab/Class.hs+24−18 src/Idris/Elab/Clause.hs+8−8 src/Idris/Elab/Instance.hs+44−42 src/Idris/Elab/Record.hs+38−34 src/Idris/Elab/Rewrite.hs+27−27 src/Idris/Elab/Term.hs+48−36 src/Idris/Elab/Type.hs+31−14 src/Idris/Elab/Utils.hs+8−8 src/Idris/ElabDecls.hs+3−3 src/Idris/Erasure.hs+16−15 src/Idris/ErrReverse.hs+6−8 src/Idris/Help.hs+16−16 src/Idris/IBC.hs+59−58 src/Idris/Imports.hs+2−2 src/Idris/Inliner.hs+2−4 src/Idris/Parser.hs+42−43 src/Idris/Parser/Data.hs+1−1 src/Idris/PartialEval.hs+51−46 src/Idris/ProofSearch.hs+21−19 src/Idris/Transforms.hs+17−19
src/Idris/ASTUtils.hs+14−19
@@ -1,6 +1,6 @@
11module Idris.ASTUtils(Field(), cg_usedpos, ctxt_lookup, fgetState, fmodifyState,
22 fputState, idris_fixities, ist_callgraph, ist_optimisation,
3− known_classes, known_terms, opt_detaggable, opt_inaccessible,
3+ known_classes, known_terms, opt_detaggable, opt_inaccessible,
44 opts_idrisCmdline, repl_definitions) where
55
66-- This implements just a few basic lens-like concepts to ease state updates.
@@ -65,8 +65,9 @@ fputState field x = fmodifyState field (const x)
6565fmodifyState :: MonadState s m => Field s a -> (a -> a) -> m ()
6666fmodifyState field f = modify $ fmodify field f
6767
68−-- Exact-name context lookup; uses Nothing for deleted values (read+write!).
69−--
68+-- | Exact-name context lookup; uses Nothing for deleted values
69+-- (read+write!).
70+--
7071-- Reading a non-existing value yields Nothing,
7172-- writing Nothing deletes the value (if it existed).
7273ctxt_lookup :: Name -> Field (Ctxt a) (Maybe a)
@@ -93,7 +94,7 @@ maybe_default dflt = Field (fromMaybe dflt) (const . Just)
9394-- OptInfo
9495----------
9596
96−-- the optimisation record for the given (exact) name
97+-- | the optimisation record for the given (exact) name
9798ist_optimisation :: Name -> Field IState OptInfo
9899ist_optimisation n =
99100 maybe_default Optimise
@@ -103,7 +104,7 @@ ist_optimisation n =
103104 . ctxt_lookup n
104105 . Field idris_optimisation (\v ist -> ist{ idris_optimisation = v })
105106
106−-- two fields of the optimisation record
107+-- | two fields of the optimisation record
107108opt_inaccessible :: Field OptInfo [(Int, Name)]
108109opt_inaccessible = Field inaccessible (\v opt -> opt{ inaccessible = v })
109110
@@ -111,10 +112,7 @@ opt_detaggable :: Field OptInfo Bool
111112opt_detaggable = Field detaggable (\v opt -> opt{ detaggable = v })
112113
113114
114−-- CGInfo
115−---------
116−
117−-- callgraph record for the given (exact) name
115+-- | callgraph record for the given (exact) name
118116ist_callgraph :: Name -> Field IState CGInfo
119117ist_callgraph n =
120118 maybe_default CGInfo
@@ -126,18 +124,16 @@ ist_callgraph n =
126124cg_usedpos :: Field CGInfo [(Int, [UsageReason])]
127125cg_usedpos = Field usedpos (\v cg -> cg{ usedpos = v })
128126
129−-- Commandline flags
130−--------------------
131−
127+-- | Commandline flags
132128opts_idrisCmdline :: Field IState [Opt]
133129opts_idrisCmdline =
134130 Field opt_cmdline (\v opts -> opts{ opt_cmdline = v })
135131 . Field idris_options (\v ist -> ist{ idris_options = v })
136132
137−-- TT Context
138−-------------
139−-- This has a terrible name, but I'm not sure of a better one that isn't
140−-- confusingly close to tt_ctxt
133+-- | TT Context
134+--
135+-- This has a terrible name, but I'm not sure of a better one that
136+-- isn't confusingly close to tt_ctxt
141137known_terms :: Field IState (Ctxt (Def, Injectivity, Accessibility, Totality, MetaInformation))
142138known_terms = Field (definitions . tt_ctxt)
143139 (\v state -> state {tt_ctxt = (tt_ctxt state) {definitions = v}})
@@ -146,11 +142,10 @@ known_classes :: Field IState (Ctxt ClassInfo)
146142known_classes = Field idris_classes (\v state -> state {idris_classes = idris_classes state})
147143
148144
149−-- Names defined at the repl
150−----------------------------
145+-- | Names defined at the repl
151146repl_definitions :: Field IState [Name]
152147repl_definitions = Field idris_repl_defs (\v state -> state {idris_repl_defs = v})
153148
154−-- Fixity declarations in an IState
149+-- | Fixity declarations in an IState
155150idris_fixities :: Field IState [FixDecl]
156151idris_fixities = Field idris_infixes (\v state -> state {idris_infixes = v})
src/Idris/AbsSyntax.hs+40−37
@@ -145,8 +145,8 @@ addLangExt ErrorReflection = do i <- getIState
145145 idris_language_extensions = ErrorReflection : idris_language_extensions i
146146 }
147147
148−-- Transforms are organised by the function being applied on the lhs of the
149−-- transform, to make looking up appropriate transforms quicker
148+-- | Transforms are organised by the function being applied on the lhs
149+-- of the transform, to make looking up appropriate transforms quicker
150150addTrans :: Name -> (Term, Term) -> Idris ()
151151addTrans basefn t
152152 = do i <- getIState
@@ -331,8 +331,8 @@ isTyInferred n
331331 [TIPartial] -> return True
332332 _ -> return False
333333
334−-- | Adds error handlers for a particular function and argument. If names are
335−-- ambiguous, all matching handlers are updated.
334+-- | Adds error handlers for a particular function and argument. If
335+-- names are ambiguous, all matching handlers are updated.
336336addFunctionErrorHandlers :: Name -> Name -> [Name] -> Idris ()
337337addFunctionErrorHandlers f arg hs =
338338 do i <- getIState
@@ -350,7 +350,7 @@ getFunctionErrorHandlers f arg = do i <- getIState
350350 undefined --lookup arg =<< lookupCtxtExact f (idris_function_errorhandlers i)
351351
352352
353−-- Trace all the names in a call graph starting at the given name
353+-- | Trace all the names in a call graph starting at the given name
354354getAllNames :: Name -> Idris [Name]
355355getAllNames n = allNames [] n
356356
@@ -456,12 +456,11 @@ addInstance int res n i
456456 chaser (NS n _) = chaser n
457457 chaser _ = False
458458
459−-- Add a privileged implementation - one which instance search will happily
460−-- resolve immediately if it is type correct
461−-- This is used for naming parent implementations when defining an
462−-- implementation with constraints.
463−-- Returns the old list, so we can revert easily at the end of a block
464−
459+-- | Add a privileged implementation - one which instance search will
460+-- happily resolve immediately if it is type correct This is used for
461+-- naming parent implementations when defining an implementation with
462+-- constraints. Returns the old list, so we can revert easily at the
463+-- end of a block
465464addOpenImpl :: [Name] -> Idris [Name]
466465addOpenImpl ns = do ist <- getIState
467466 ns' <- mapM (checkValid ist) ns
@@ -530,7 +529,7 @@ resetNameIdx :: Idris ()
530529resetNameIdx = do i <- getIState
531530 put (i { idris_nameIdx = (0, emptyContext) })
532531
533−-- Used to preserve sharing of names
532+-- | Used to preserve sharing of names
534533addNameIdx :: Name -> Idris (Int, Name)
535534addNameIdx n = do i <- getIState
536535 let (i', x) = addNameIdx' i n
@@ -597,7 +596,8 @@ withContext ctx name dflt action = do
597596withContext_ :: (IState -> Ctxt a) -> Name -> (a -> Idris ()) -> Idris ()
598597withContext_ ctx name action = withContext ctx name () action
599598
600−-- | A version of liftIO that puts errors into the exception type of the Idris monad
599+-- | A version of liftIO that puts errors into the exception type of
600+-- the Idris monad
601601runIO :: IO a -> Idris a
602602runIO x = liftIO (tryIOError x) >>= either (throwError . Msg . show) return
603603-- TODO: create specific Idris exceptions for specific IO errors such as "openFile: does not exist"
@@ -611,8 +611,10 @@ getName = do i <- getIState;
611611 putIState $ (i { idris_name = idx + 1 })
612612 return idx
613613
614−-- InternalApp keeps track of the real function application for making case splits from, not the application the
615−-- programmer wrote, which doesn't have the whole context in any case other than top level definitions
614+-- | InternalApp keeps track of the real function application for
615+-- making case splits from, not the application the programmer wrote,
616+-- which doesn't have the whole context in any case other than top
617+-- level definitions
616618addInternalApp :: FilePath -> Int -> PTerm -> Idris ()
617619addInternalApp fp l t
618620 = do i <- getIState
@@ -637,16 +639,17 @@ getInternalApp fp l = do i <- getIState
637639 -- TODO: What if it's not there?
638640 else return Placeholder
639641
640−-- Pattern definitions are only used for coverage checking, so erase them
641−-- when we're done
642+-- | Pattern definitions are only used for coverage checking, so erase
643+-- them when we're done
642644clearOrigPats :: Idris ()
643645clearOrigPats = do i <- get
644646 let ps = idris_patdefs i
645647 let ps' = mapCtxt (\ (_,miss) -> ([], miss)) ps
646648 put (i { idris_patdefs = ps' })
647649
648−-- Erase types from Ps in the context (basically ending up with what's in
649−-- the .ibc, which is all we need after all the analysis is done)
650+-- | Erase types from Ps in the context (basically ending up with
651+-- what's in the .ibc, which is all we need after all the analysis is
652+-- done)
650653clearPTypes :: Idris ()
651654clearPTypes = do i <- get
652655 let ctxt = tt_ctxt i
@@ -866,8 +869,8 @@ removeOptimise :: Optimisation -> Idris ()
866869removeOptimise opt = do opts <- getOptimise
867870 setOptimise ((nub opts) \\ [opt])
868871
869−-- Set appropriate optimisation set for the given level. We only have
870−-- one optimisation that is configurable at the moment, however!
872+-- | Set appropriate optimisation set for the given level. We only
873+-- have one optimisation that is configurable at the moment, however!
871874setOptLevel :: Int -> Idris ()
872875setOptLevel n | n <= 0 = setOptimise []
873876setOptLevel 1 = setOptimise []
@@ -1350,12 +1353,11 @@ expandInstanceScope ist dec ps ns (PInstance doc argDocs info f cs pnames acc op
13501353 ty cn decls
13511354expandInstanceScope ist dec ps ns d = d
13521355
1353−-- Calculate a priority for a type, for deciding elaboration order
1356+-- | Calculate a priority for a type, for deciding elaboration order
13541357-- * if it's just a type variable or concrete type, do it early (0)
13551358-- * if there's only type variables and injective constructors, do it next (1)
13561359-- * if there's a function type, next (2)
13571360-- * finally, everything else (3)
1358−
13591361getPriority :: IState -> PTerm -> Int
13601362getPriority i tm = 1 -- pri tm
13611363 where
@@ -1501,7 +1503,7 @@ addUsingConstraints syn fc t
15011503 getName (PExp _ _ _ (PRef _ _ n)) = return n
15021504 getName _ = []
15031505
1504−-- Add implicit bindings from using block, and bind any missing names
1506+-- | Add implicit bindings from using block, and bind any missing names
15051507addUsingImpls :: SyntaxInfo -> Name -> FC -> PTerm -> Idris PTerm
15061508addUsingImpls syn n fc t
15071509 = do ist <- getIState
@@ -1623,8 +1625,8 @@ implicit' info syn ignore n ptm
16231625 notFound kns (SN (WhereN _ _ _) : ns) = notFound kns ns -- Known already
16241626 notFound kns (n:ns) = if elem n kns then notFound kns ns else Just n
16251627
1626−-- Even if auto_implicits is off, we need to call this so we record which
1627−-- arguments are implicit
1628+-- | Even if auto_implicits is off, we need to call this so we record
1629+-- which arguments are implicit
16281630implicitise :: Bool -> SyntaxInfo -> [Name] -> IState -> PTerm -> (PTerm, [PArg])
16291631implicitise auto syn ignore ist tm = -- trace ("INCOMING " ++ showImp True tm) $
16301632 let (declimps, ns') = execState (imps True [] tm) ([], [])
@@ -1729,7 +1731,7 @@ implicitise auto syn ignore ist tm = -- trace ("INCOMING " ++ showImp True tm) $
17291731 Nothing -> PPi (Imp [InaccessibleArg] Dynamic False (Just (Impl False True)) False)
17301732 n NoFC Placeholder (pibind using ns sc)
17311733
1732−-- Add implicit arguments in function calls
1734+-- | Add implicit arguments in function calls
17331735addImplPat :: IState -> PTerm -> PTerm
17341736addImplPat = addImpl' True [] [] []
17351737
@@ -1739,10 +1741,10 @@ addImplBound ist ns = addImpl' False ns [] [] ist
17391741addImplBoundInf :: IState -> [Name] -> [Name] -> PTerm -> PTerm
17401742addImplBoundInf ist ns inf = addImpl' False ns inf [] ist
17411743
1742−-- | Add the implicit arguments to applications in the term
1743−-- [Name] gives the names to always expend, even when under a binder of
1744−-- that name (this is to expand methods with implicit arguments in dependent
1745−-- type classes).
1744+-- | Add the implicit arguments to applications in the term [Name]
1745+-- gives the names to always expend, even when under a binder of that
1746+-- name (this is to expand methods with implicit arguments in
1747+-- dependent type classes).
17461748addImpl :: [Name] -> IState -> PTerm -> PTerm
17471749addImpl = addImpl' False [] []
17481750
@@ -2006,8 +2008,8 @@ aiFn topname inpat expat qq imp_meths ist fc f ffc ds as
20062008 | n == n' = Just (t, reverse acc ++ gs)
20072009 find n (g : gs) acc = find n gs (g : acc)
20082010
2009−-- return True if the second argument is an implicit argument which is
2010−-- expected in the implicits, or if it's not an implicit
2011+-- | return True if the second argument is an implicit argument which
2012+-- is expected in the implicits, or if it's not an implicit
20112013impIn :: [PArg] -> PArg -> Bool
20122014impIn ps (PExp _ _ _ _) = True
20132015impIn ps (PConstraint _ _ _ _) = True
@@ -2115,11 +2117,12 @@ mkPApp fc a f as = let rest = drop a as in
21152117 appRest fc f [] = f
21162118 appRest fc f (a : as) = appRest fc (PApp fc f [a]) as
21172119
2118−-- Find 'static' argument positions
2120+
2121+
2122+-- | Find 'static' argument positions
21192123-- (the declared ones, plus any names in argument position in the declared
21202124-- statics)
21212125-- FIXME: It's possible that this really has to happen after elaboration
2122−
21232126findStatics :: IState -> PTerm -> (PTerm, [Bool])
21242127findStatics ist tm = let (ns, ss) = fs tm
21252128 in runState (pos ns ss tm) []
@@ -2350,8 +2353,8 @@ shadow n n' t = sm 0 t where
23502353 update oldn | n == oldn = n'
23512354 | otherwise = oldn
23522355
2353−-- | Rename any binders which are repeated (so that we don't have to mess
2354−-- about with shadowing anywhere else).
2356+-- | Rename any binders which are repeated (so that we don't have to
2357+-- mess about with shadowing anywhere else).
23552358mkUniqueNames :: [Name] -> [(Name, Name)] -> PTerm -> PTerm
23562359mkUniqueNames env shadows tm
23572360 = evalState (mkUniq 0 initMap tm) (S.fromList env) where
src/Idris/AbsSyntaxTree.hs+496−412
@@ -48,23 +48,24 @@ import Text.PrettyPrint.Annotated.Leijen
4848data ElabWhat = ETypes | EDefns | EAll
4949 deriving (Show, Eq)
5050
51−-- Data to pass to recursively called elaborators; e.g. for where blocks,
51+-- | Data to pass to recursively called elaborators; e.g. for where blocks,
5252-- paramaterised declarations, etc.
53−
53+--
5454-- rec_elabDecl is used to pass the top level elaborator into other elaborators,
5555-- so that we can have mutually recursive elaborators in separate modules without
5656-- having to muck about with cyclic modules.
57−data ElabInfo = EInfo { params :: [(Name, PTerm)],
58− inblock :: Ctxt [Name], -- names in the block, and their params
59− liftname :: Name -> Name,
60− namespace :: Maybe [String],
61− elabFC :: Maybe FC,
62− -- We may, recursively, collect transformations to
63− -- do on the rhs, e.g. rewriting recursive calls to
64− -- functions defined by 'with'
65− rhs_trans :: PTerm -> PTerm,
66− rec_elabDecl :: ElabWhat -> ElabInfo -> PDecl ->
67− Idris () }
57+data ElabInfo = EInfo {
58+ params :: [(Name, PTerm)]
59+ , inblock :: Ctxt [Name] -- ^ names in the block, and their params
60+ , liftname :: Name -> Name
61+ , namespace :: Maybe [String]
62+ , elabFC :: Maybe FC
63+
64+ -- | We may, recursively, collect transformations to do on the rhs,
65+ -- e.g. rewriting recursive calls to functions defined by 'with'
66+ , rhs_trans :: PTerm -> PTerm
67+ , rec_elabDecl :: ElabWhat -> ElabInfo -> PDecl -> Idris ()
68+ }
6869
6970toplevel :: ElabInfo
7071toplevel = EInfo [] emptyContext id Nothing Nothing id (\_ _ _ -> fail "Not implemented")
@@ -90,13 +91,13 @@ data IOption = IOption {
9091 , opt_importdirs :: [FilePath]
9192 , opt_triple :: String
9293 , opt_cpu :: String
93− , opt_cmdline :: [Opt] -- remember whole command line
94+ , opt_cmdline :: [Opt] -- ^ remember whole command line
9495 , opt_origerr :: Bool
9596 , opt_autoSolve :: Bool -- ^ automatically apply "solve" tactic in prover
96− , opt_autoImport :: [FilePath] -- ^ e.g. Builtins+Prelude
97+ , opt_autoImport :: [FilePath] -- ^ List of modules to auto import i.e. `Builtins+Prelude`
9798 , opt_optimise :: [Optimisation]
9899 , opt_printdepth :: Maybe Int
99− , opt_evaltypes :: Bool -- ^ normalise types in :t
100+ , opt_evaltypes :: Bool -- ^ normalise types in `:t`
100101 , opt_desugarnats :: Bool
101102 , opt_autoimpls :: Bool
102103 } deriving (Show, Eq)
@@ -130,39 +131,43 @@ defaultOpts = IOption { opt_logLevel = 0
130131 }
131132
132133data PPOption = PPOption {
133− ppopt_impl :: Bool -- ^^ whether to show implicits
134+ ppopt_impl :: Bool -- ^ whether to show implicits
134135 , ppopt_desugarnats :: Bool
135− , ppopt_pinames :: Bool -- ^^ whether to show names in pi bindings
136− , ppopt_depth :: Maybe Int
137−} deriving (Show)
136+ , ppopt_pinames :: Bool -- ^ whether to show names in pi bindings
137+ , ppopt_depth :: Maybe Int
138+ } deriving (Show)
138139
139−data Optimisation = PETransform -- partial eval and associated transforms
140+data Optimisation = PETransform -- ^ partial eval and associated transforms
140141 deriving (Show, Eq)
141142
142143defaultOptimise = [PETransform]
143144
144145-- | Pretty printing options with default verbosity.
145146defaultPPOption :: PPOption
146−defaultPPOption = PPOption { ppopt_impl = False,
147− ppopt_desugarnats = False,
148− ppopt_pinames = False,
149− ppopt_depth = Just 200 }
147+defaultPPOption = PPOption {
148+ ppopt_impl = False
149+ , ppopt_desugarnats = False
150+ , ppopt_pinames = False
151+ , ppopt_depth = Just 200
152+ }
150153
151154-- | Pretty printing options with the most verbosity.
152155verbosePPOption :: PPOption
153−verbosePPOption = PPOption { ppopt_impl = True,
154− ppopt_desugarnats = True,
155− ppopt_pinames = True,
156− ppopt_depth = Just 200 }
156+verbosePPOption = PPOption {
157+ ppopt_impl = True
158+ , ppopt_desugarnats = True
159+ , ppopt_pinames = True
160+ , ppopt_depth = Just 200
161+ }
157162
158163-- | Get pretty printing options from the big options record.
159164ppOption :: IOption -> PPOption
160165ppOption opt = PPOption {
161− ppopt_impl = opt_showimp opt,
162− ppopt_pinames = False,
163− ppopt_depth = opt_printdepth opt,
164− ppopt_desugarnats = opt_desugarnats opt
165−}
166+ ppopt_impl = opt_showimp opt
167+ , ppopt_pinames = False
168+ , ppopt_depth = opt_printdepth opt
169+ , ppopt_desugarnats = opt_desugarnats opt
170+ }
166171
167172-- | Get pretty printing options from an idris state record.
168173ppOptionIst :: IState -> PPOption
@@ -171,13 +176,13 @@ ppOptionIst = ppOption . idris_options
171176data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord)
172177
173178-- | The output mode in use
174−data OutputMode = RawOutput Handle -- ^ Print user output directly to the handle
179+data OutputMode = RawOutput Handle -- ^ Print user output directly to the handle
175180 | IdeMode Integer Handle -- ^ Send IDE output for some request ID to the handle
176181 deriving Show
177182
178183-- | How wide is the console?
179184data ConsoleWidth = InfinitelyWide -- ^ Have pretty-printer assume that lines should not be broken
180− | ColsWide Int -- ^ Manually specified - must be positive
185+ | ColsWide Int -- ^ Manually specified - must be positive
181186 | AutomaticWidth -- ^ Attempt to determine width, or 80 otherwise
182187 deriving (Show, Eq)
183188
@@ -189,97 +194,105 @@ data DefaultTotality = DefaultCheckingTotal -- ^ Total
189194
190195-- | The global state used in the Idris monad
191196data IState = IState {
192− tt_ctxt :: Context, -- ^ All the currently defined names and their terms
193− idris_constraints :: S.Set ConstraintFC,
194− -- ^ A list of universe constraints and their corresponding source locations
195− idris_infixes :: [FixDecl], -- ^ Currently defined infix operators
196− idris_implicits :: Ctxt [PArg],
197− idris_statics :: Ctxt [Bool],
198− idris_classes :: Ctxt ClassInfo,
199− idris_openimpls :: [Name], -- ^ Privileged implementations, will resolve immediately
200− idris_records :: Ctxt RecordInfo,
201− idris_dsls :: Ctxt DSL,
202− idris_optimisation :: Ctxt OptInfo,
203− idris_datatypes :: Ctxt TypeInfo,
204− idris_namehints :: Ctxt [Name],
205− idris_patdefs :: Ctxt ([([(Name, Term)], Term, Term)], [PTerm]), -- not exported
206− -- ^ list of lhs/rhs, and a list of missing clauses
207− idris_flags :: Ctxt [FnOpt],
208− idris_callgraph :: Ctxt CGInfo, -- name, args used in each pos
209− idris_docstrings :: Ctxt (Docstring DocTerm, [(Name, Docstring DocTerm)]),
210− idris_moduledocs :: Ctxt (Docstring DocTerm),
211− -- ^ module documentation is saved in a special MN so the context
212− -- mechanism can be used for disambiguation
213− idris_tyinfodata :: Ctxt TIData,
214− idris_fninfo :: Ctxt FnInfo,
215− idris_transforms :: Ctxt [(Term, Term)],
216− idris_autohints :: Ctxt [Name],
217− idris_totcheck :: [(FC, Name)], -- names to check totality on
218− idris_defertotcheck :: [(FC, Name)], -- names to check at the end
219− idris_totcheckfail :: [(FC, String)],
220− idris_options :: IOption,
221− idris_name :: Int,
222− idris_lineapps :: [((FilePath, Int), PTerm)],
223− -- ^ Full application LHS on source line
224− idris_metavars :: [(Name, (Maybe Name, Int, [Name], Bool, Bool))],
225− -- ^ The currently defined but not proven metavariables. The Int
226− -- is the number of vars to display as a context, the Maybe Name
227− -- is its top-level function, the [Name] is the list of local variables
228− -- available for proof search and the Bools are whether :p is
229− -- allowed, and whether the variable is definable at all
230− -- (Metavariables are not definable if they are applied in a term which
231− -- still has hole bindings)
232− idris_coercions :: [Name],
233− idris_errRev :: [(Term, Term)],
234− syntax_rules :: SyntaxRules,
235− syntax_keywords :: [String],
236− imported :: [FilePath], -- ^ The imported modules
237− idris_scprims :: [(Name, (Int, PrimFn))],
238− idris_objs :: [(Codegen, FilePath)],
239− idris_libs :: [(Codegen, String)],
240− idris_cgflags :: [(Codegen, String)],
241− idris_hdrs :: [(Codegen, String)],
242− idris_imported :: [(FilePath, Bool)], -- ^ Imported ibc file names, whether public
243− proof_list :: [(Name, (Bool, [String]))],
244− errSpan :: Maybe FC,
245− parserWarnings :: [(FC, Err)],
246− lastParse :: Maybe Name,
247− indent_stack :: [Int],
248− brace_stack :: [Maybe Int],
249− lastTokenSpan :: Maybe FC, -- ^ What was the span of the latest token parsed?
250− idris_parsedSpan :: Maybe FC,
251− hide_list :: Ctxt Accessibility,
252− default_access :: Accessibility,
253− default_total :: DefaultTotality,
254− ibc_write :: [IBCWrite],
255− compiled_so :: Maybe String,
256− idris_dynamic_libs :: [DynamicLib],
257− idris_language_extensions :: [LanguageExt],
258− idris_outputmode :: OutputMode,
259− idris_colourRepl :: Bool,
260− idris_colourTheme :: ColourTheme,
261− idris_errorhandlers :: [Name], -- ^ Global error handlers
262− idris_nameIdx :: (Int, Ctxt (Int, Name)),
263− idris_function_errorhandlers :: Ctxt (M.Map Name (S.Set Name)), -- ^ Specific error handlers
264− module_aliases :: M.Map [T.Text] [T.Text],
265− idris_consolewidth :: ConsoleWidth, -- ^ How many chars wide is the console?
266− idris_postulates :: S.Set Name,
267− idris_externs :: S.Set (Name, Int),
268− idris_erasureUsed :: [(Name, Int)], -- ^ Function/constructor name, argument position is used
269− idris_whocalls :: Maybe (M.Map Name [Name]),
270− idris_callswho :: Maybe (M.Map Name [Name]),
271− idris_repl_defs :: [Name], -- ^ List of names that were defined in the repl, and can be re-/un-defined
272− elab_stack :: [(Name, Bool)], -- ^ Stack of names currently being elaborated, Bool set if it's an instance
273− -- (instances appear twice; also as a funtion name)
274− idris_symbols :: M.Map Name Name, -- ^ Symbol table (preserves sharing of names)
275− idris_exports :: [Name], -- ^ Functions with ExportList
276− idris_highlightedRegions :: [(FC, OutputAnnotation)], -- ^ Highlighting information to output
277− idris_parserHighlights :: [(FC, OutputAnnotation)], -- ^ Highlighting information from the parser
278− idris_deprecated :: Ctxt String, -- ^ Deprecated names and explanation
279− idris_inmodule :: S.Set Name, -- ^ Names defined in current module
280− idris_ttstats :: M.Map Term (Int, Term),
281− idris_fragile :: Ctxt String -- ^ Fragile names and explanation.
282− }
197+ tt_ctxt :: Context -- ^ All the currently defined names and their terms
198+ , idris_constraints :: S.Set ConstraintFC -- ^ A list of universe constraints and their corresponding source locations
199+ , idris_infixes :: [FixDecl] -- ^ Currently defined infix operators
200+ , idris_implicits :: Ctxt [PArg]
201+ , idris_statics :: Ctxt [Bool]
202+ , idris_classes :: Ctxt ClassInfo
203+ , idris_openimpls :: [Name] -- ^ Privileged implementations, will resolve immediately
204+ , idris_records :: Ctxt RecordInfo
205+ , idris_dsls :: Ctxt DSL
206+ , idris_optimisation :: Ctxt OptInfo
207+ , idris_datatypes :: Ctxt TypeInfo
208+ , idris_namehints :: Ctxt [Name]
209+
210+ -- | list of lhs/rhs, and a list of missing clauses. These are not
211+ -- exported.
212+ , idris_patdefs :: Ctxt ([([(Name, Term)], Term, Term)], [PTerm])
213+ , idris_flags :: Ctxt [FnOpt]
214+ , idris_callgraph :: Ctxt CGInfo -- ^ name, args used in each pos
215+ , idris_docstrings :: Ctxt (Docstring DocTerm, [(Name, Docstring DocTerm)])
216+
217+ -- | module documentation is saved in a special MN so the context
218+ -- mechanism can be used for disambiguation.
219+ , idris_moduledocs :: Ctxt (Docstring DocTerm)
220+ , idris_tyinfodata :: Ctxt TIData
221+ , idris_fninfo :: Ctxt FnInfo
222+ , idris_transforms :: Ctxt [(Term, Term)]
223+ , idris_autohints :: Ctxt [Name]
224+ , idris_totcheck :: [(FC, Name)] -- ^ names to check totality on
225+ , idris_defertotcheck :: [(FC, Name)] -- ^ names to check at the end
226+ , idris_totcheckfail :: [(FC, String)]
227+ , idris_options :: IOption
228+ , idris_name :: Int
229+ , idris_lineapps :: [((FilePath, Int), PTerm)] -- ^ Full application LHS on source line
230+
231+ -- | The currently defined but not proven metavariables. The Int is
232+ -- the number of vars to display as a context, the Maybe Name is its
233+ -- top-level function, the [Name] is the list of local variables
234+ -- available for proof search and the Bools are whether :p is
235+ -- allowed, and whether the variable is definable at all
236+ -- (Metavariables are not definable if they are applied in a term
237+ -- which still has hole bindings)
238+ , idris_metavars :: [(Name, (Maybe Name, Int, [Name], Bool, Bool))]
239+ , idris_coercions :: [Name]
240+ , idris_errRev :: [(Term, Term)]
241+ , syntax_rules :: SyntaxRules
242+ , syntax_keywords :: [String]
243+ , imported :: [FilePath] -- ^ The imported modules
244+ , idris_scprims :: [(Name, (Int, PrimFn))]
245+ , idris_objs :: [(Codegen, FilePath)]
246+ , idris_libs :: [(Codegen, String)]
247+ , idris_cgflags :: [(Codegen, String)]
248+ , idris_hdrs :: [(Codegen, String)]
249+ , idris_imported :: [(FilePath, Bool)] -- ^ Imported ibc file names, whether public
250+ , proof_list :: [(Name, (Bool, [String]))]
251+ , errSpan :: Maybe FC
252+ , parserWarnings :: [(FC, Err)]
253+ , lastParse :: Maybe Name
254+ , indent_stack :: [Int]
255+ , brace_stack :: [Maybe Int]
256+ , lastTokenSpan :: Maybe FC -- ^ What was the span of the latest token parsed?
257+ , idris_parsedSpan :: Maybe FC
258+ , hide_list :: Ctxt Accessibility
259+ , default_access :: Accessibility
260+ , default_total :: DefaultTotality
261+ , ibc_write :: [IBCWrite]
262+ , compiled_so :: Maybe String
263+ , idris_dynamic_libs :: [DynamicLib]
264+ , idris_language_extensions :: [LanguageExt]
265+ , idris_outputmode :: OutputMode
266+ , idris_colourRepl :: Bool
267+ , idris_colourTheme :: ColourTheme
268+ , idris_errorhandlers :: [Name] -- ^ Global error handlers
269+ , idris_nameIdx :: (Int, Ctxt (Int, Name))
270+ , idris_function_errorhandlers :: Ctxt (M.Map Name (S.Set Name)) -- ^ Specific error handlers
271+ , module_aliases :: M.Map [T.Text] [T.Text]
272+ , idris_consolewidth :: ConsoleWidth -- ^ How many chars wide is the console?
273+ , idris_postulates :: S.Set Name
274+ , idris_externs :: S.Set (Name, Int)
275+ , idris_erasureUsed :: [(Name, Int)] -- ^ Function/constructor name, argument position is used
276+ , idris_whocalls :: Maybe (M.Map Name [Name])
277+ , idris_callswho :: Maybe (M.Map Name [Name])
278+
279+ -- | List of names that were defined in the repl, and can be re-/un-defined
280+ , idris_repl_defs :: [Name]
281+
282+ -- | Stack of names currently being elaborated, Bool set if it's an
283+ -- instance (instances appear twice; also as a funtion name)
284+ , elab_stack :: [(Name, Bool)]
285+
286+
287+ , idris_symbols :: M.Map Name Name -- ^ Symbol table (preserves sharing of names)
288+ , idris_exports :: [Name] -- ^ Functions with ExportList
289+ , idris_highlightedRegions :: [(FC, OutputAnnotation)] -- ^ Highlighting information to output
290+ , idris_parserHighlights :: [(FC, OutputAnnotation)] -- ^ Highlighting information from the parser
291+ , idris_deprecated :: Ctxt String -- ^ Deprecated names and explanation
292+ , idris_inmodule :: S.Set Name -- ^ Names defined in current module
293+ , idris_ttstats :: M.Map Term (Int, Term)
294+ , idris_fragile :: Ctxt String -- ^ Fragile names and explanation.
295+ }
283296
284297-- Required for parsers library, and therefore trifecta
285298instance Show IState where
@@ -295,20 +308,21 @@ deriving instance NFData SizeChange
295308type SCGEntry = (Name, [Maybe (Int, SizeChange)])
296309type UsageReason = (Name, Int) -- fn_name, its_arg_number
297310
298−data CGInfo = CGInfo { calls :: [Name],
299− scg :: [SCGEntry],
300− usedpos :: [(Int, [UsageReason])]
301− }
302− deriving Show
311+data CGInfo = CGInfo {
312+ calls :: [Name]
313+ , scg :: [SCGEntry]
314+ , usedpos :: [(Int, [UsageReason])]
315+ } deriving Show
303316{-!
304317deriving instance Binary CGInfo
305318deriving instance NFData CGInfo
306319!-}
307320
308−primDefs = [sUN "unsafePerformPrimIO",
309− sUN "mkLazyForeignPrim",
310− sUN "mkForeignPrim",
311− sUN "void"]
321+primDefs = [ sUN "unsafePerformPrimIO"
322+ , sUN "mkLazyForeignPrim"
323+ , sUN "mkForeignPrim"
324+ , sUN "void"
325+ ]
312326
313327-- information that needs writing for the current module's .ibc file
314328data IBCWrite = IBCFix FixDecl
@@ -323,7 +337,7 @@ data IBCWrite = IBCFix FixDecl
323337 | IBCMetavar Name
324338 | IBCSyntax Syntax
325339 | IBCKeyword String
326− | IBCImport (Bool, FilePath) -- True = import public
340+ | IBCImport (Bool, FilePath) -- ^ True = import public
327341 | IBCImportDir FilePath
328342 | IBCObj Codegen FilePath
329343 | IBCLib Codegen String
@@ -341,7 +355,7 @@ data IBCWrite = IBCFix FixDecl
341355 | IBCCG Name
342356 | IBCDoc Name
343357 | IBCCoercion Name
344− | IBCDef Name -- i.e. main context
358+ | IBCDef Name -- ^ The main context.
345359 | IBCNameHint (Name, Name)
346360 | IBCLineApp FilePath Int PTerm
347361 | IBCErrorHandler Name
@@ -373,9 +387,13 @@ idrisInit = IState initContext S.empty []
373387 emptyContext S.empty M.empty emptyContext
374388
375389
376−-- | The monad for the main REPL - reading and processing files and updating
377−-- global state (hence the IO inner monad).
378−--type Idris = WriterT [Either String (IO ())] (State IState a))
390+-- | The monad for the main REPL - reading and processing files and
391+-- updating global state (hence the IO inner monad).
392+--
393+-- @
394+-- type Idris = WriterT [Either String (IO ())] (State IState a))
395+-- @
396+--
379397type Idris = StateT IState (ExceptT Err IO)
380398
381399catchError :: Idris a -> (Err -> Idris a) -> Idris a
@@ -441,10 +459,10 @@ data Command = Quit
441459 | MakeWith Bool Int Name
442460 | MakeCase Bool Int Name
443461 | MakeLemma Bool Int Name
444− | DoProofSearch Bool -- update file
445− Bool -- recursive search
446− Int -- depth
447− Name -- top level name
462+ | DoProofSearch Bool -- update file
463+ Bool -- recursive search
464+ Int -- depth
465+ Name -- top level name
448466 [Name] -- hints
449467 | SetOpt Opt
450468 | UnsetOpt Opt
@@ -459,7 +477,7 @@ data Command = Quit
459477 | WhoCalls Name
460478 | CallsWho Name
461479 | Browse [String]
462− | MakeDoc String -- IdrisDoc
480+ | MakeDoc String -- IdrisDoc
463481 | Warranty
464482 | PrintDef Name
465483 | PPrint OutputFmt Int PTerm
@@ -538,7 +556,7 @@ data Opt = Filename String
538556 | ErrContext
539557 | ShowImpl
540558 | Verbose
541− | Port String -- REPL TCP port
559+ | Port String -- ^ REPL TCP port
542560 | IBCSubDir String
543561 | ImportDir String
544562 | PkgBuild String
@@ -546,7 +564,7 @@ data Opt = Filename String
546564 | PkgClean String
547565 | PkgCheck String
548566 | PkgREPL String
549− | PkgMkDoc String -- IdrisDoc
567+ | PkgMkDoc String -- IdrisDoc
550568 | PkgTest String
551569 | PkgIndex FilePath
552570 | WarnOnly
@@ -572,20 +590,26 @@ data Opt = Filename String
572590 | UseConsoleWidth ConsoleWidth
573591 | DumpHighlights
574592 | DesugarNats
575− | NoElimDeprecationWarnings -- ^ Don't show deprecation warnings for %elim
593+ | NoElimDeprecationWarnings -- ^ Don't show deprecation warnings for %elim
576594 | NoOldTacticDeprecationWarnings -- ^ Don't show deprecation warnings for old-style tactics
577595 deriving (Show, Eq)
578596
579−data ElabShellCmd = EQED | EAbandon | EUndo | EProofState | EProofTerm
580− | EEval PTerm | ECheck PTerm | ESearch PTerm
597+data ElabShellCmd = EQED
598+ | EAbandon
599+ | EUndo
600+ | EProofState
601+ | EProofTerm
602+ | EEval PTerm
603+ | ECheck PTerm
604+ | ESearch PTerm
581605 | EDocStr (Either Name Const)
582606 deriving (Show, Eq)
583607
584608-- Parsed declarations
585609
586−data Fixity = Infixl { prec :: Int }
587− | Infixr { prec :: Int }
588− | InfixN { prec :: Int }
610+data Fixity = Infixl { prec :: Int }
611+ | Infixr { prec :: Int }
612+ | InfixN { prec :: Int }
589613 | PrefixN { prec :: Int }
590614 deriving Eq
591615{-!
@@ -594,9 +618,9 @@ deriving instance NFData Fixity
594618!-}
595619
596620instance Show Fixity where
597− show (Infixl i) = "infixl " ++ show i
598− show (Infixr i) = "infixr " ++ show i
599− show (InfixN i) = "infix " ++ show i
621+ show (Infixl i) = "infixl " ++ show i
622+ show (Infixr i) = "infixr " ++ show i
623+ show (InfixN i) = "infix " ++ show i
600624 show (PrefixN i) = "prefix " ++ show i
601625
602626data FixDecl = Fix Fixity String
@@ -621,22 +645,25 @@ deriving instance Binary Static
621645deriving instance NFData Static
622646!-}
623647
624−-- Mark bindings with their explicitness, and laziness
625−data Plicity = Imp { pargopts :: [ArgOpt],
626− pstatic :: Static,
627− pparam :: Bool,
628− pscoped :: Maybe ImplicitInfo, -- Nothing, if top level
629− pinsource :: Bool -- Explicitly written in source
648+-- ^ Mark bindings with their explicitness, and laziness
649+data Plicity = Imp { pargopts :: [ArgOpt]
650+ , pstatic :: Static
651+ , pparam :: Bool
652+ , pscoped :: Maybe ImplicitInfo -- ^ Nothing, if top level
653+ , pinsource :: Bool -- ^ Explicitly written in source
630654 }
631− | Exp { pargopts :: [ArgOpt],
632− pstatic :: Static,
633− pparam :: Bool } -- this is a param (rather than index)
634− | Constraint { pargopts :: [ArgOpt],
635− pstatic :: Static }
636− | TacImp { pargopts :: [ArgOpt],
637− pstatic :: Static,
638− pscript :: PTerm }
639− deriving (Show, Eq, Data, Typeable)
655+ | Exp { pargopts :: [ArgOpt]
656+ , pstatic :: Static
657+ , pparam :: Bool -- ^ this is a param (rather than index)
658+ }
659+ | Constraint { pargopts :: [ArgOpt]
660+ , pstatic :: Static
661+ }
662+ | TacImp { pargopts :: [ArgOpt]
663+ , pstatic :: Static
664+ , pscript :: PTerm
665+ }
666+ deriving (Show, Eq, Data, Typeable)
640667
641668{-!
642669deriving instance Binary Plicity
@@ -645,7 +672,7 @@ deriving instance NFData Plicity
645672
646673is_scoped :: Plicity -> Maybe ImplicitInfo
647674is_scoped (Imp _ _ _ s _) = s
648−is_scoped _ = Nothing
675+is_scoped _ = Nothing
649676
650677impl = Imp [] Dynamic False (Just (Impl False True)) False
651678
@@ -659,21 +686,23 @@ constraint = Constraint [] Static
659686
660687tacimpl t = TacImp [] Dynamic t
661688
662−data FnOpt = Inlinable -- always evaluate when simplifying
689+data FnOpt = Inlinable -- ^ always evaluate when simplifying
663690 | TotalFn | PartialFn | CoveringFn
664691 | Coinductive | AssertTotal
665− | Dictionary -- type class dictionary, eval only when
666− -- a function argument, and further evaluation resutls
667− | Implicit -- implicit coercion
668− | NoImplicit -- do not apply implicit coercions
669− | CExport String -- export, with a C name
670− | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
671− | ErrorReverse -- ^^ attempt to reverse normalise before showing in error
672− | Reflection -- a reflecting function, compile-time only
673− | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
674− | Constructor -- Data constructor type
675− | AutoHint -- use in auto implicit search
676− | PEGenerated -- generated by partial evaluator
692+
693+ -- | type class dictionary, eval only when a function
694+ -- argument, and further evaluation results.
695+ | Dictionary
696+ | Implicit -- ^ implicit coercion
697+ | NoImplicit -- ^ do not apply implicit coercions
698+ | CExport String -- ^ export, with a C name
699+ | ErrorHandler -- ^ an error handler for use with the ErrorReflection extension
700+ | ErrorReverse -- ^ attempt to reverse normalise before showing in error
701+ | Reflection -- ^ a reflecting function, compile-time only
702+ | Specialise [(Name, Maybe Int)] -- ^ specialise it, freeze these names
703+ | Constructor -- ^ Data constructor type
704+ | AutoHint -- ^ use in auto implicit search
705+ | PEGenerated -- ^ generated by partial evaluator
677706 deriving (Show, Eq)
678707{-!
679708deriving instance Binary FnOpt
@@ -699,67 +728,84 @@ type ProvideWhat = ProvideWhat' PTerm
699728-- | Top-level declarations such as compiler directives, definitions,
700729-- datatypes and typeclasses.
701730data PDecl' t
702− = PFix FC Fixity [String] -- ^ Fixity declaration
703− | PTy (Docstring (Either Err t)) [(Name, Docstring (Either Err t))] SyntaxInfo FC FnOpts Name FC t -- ^ Type declaration (last FC is precise name location)
731+ -- | Fixity declaration
732+ = PFix FC Fixity [String]
733+ -- | Type declaration (last FC is precise name location)
734+ | PTy (Docstring (Either Err t)) [(Name, Docstring (Either Err t))] SyntaxInfo FC FnOpts Name FC t
735+ -- | Postulate, second FC is precise name location
704736 | PPostulate Bool -- external def if true
705− (Docstring (Either Err t)) SyntaxInfo FC FC FnOpts Name t -- ^ Postulate, second FC is precise name location
706− | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
707− | PCAF FC Name t -- ^ Top level constant
708− | PData (Docstring (Either Err t)) [(Name, Docstring (Either Err t))] SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
709− | PParams FC [(Name, t)] [PDecl' t] -- ^ Params block
710− | POpenInterfaces FC [Name] [PDecl' t] -- ^ Open block/declaration
737+ (Docstring (Either Err t)) SyntaxInfo FC FC FnOpts Name t
738+ -- | Pattern clause
739+ | PClauses FC FnOpts Name [PClause' t]
740+ -- | Top level constant
741+ | PCAF FC Name t
742+ -- | Data declaration.
743+ | PData (Docstring (Either Err t)) [(Name, Docstring (Either Err t))] SyntaxInfo FC DataOpts (PData' t)
744+ -- | Params block
745+ | PParams FC [(Name, t)] [PDecl' t]
746+ -- | Open block/declaration
747+ | POpenInterfaces FC [Name] [PDecl' t]
748+ -- | New namespace, where FC is accurate location of the namespace
749+ -- in the file
711750 | PNamespace String FC [PDecl' t]
712− -- ^ New namespace, where FC is accurate location of the
713− -- namespace in the file
714− | PRecord (Docstring (Either Err t)) SyntaxInfo FC DataOpts
715− Name -- Record name
716− FC -- Record name precise location
717− [(Name, FC, Plicity, t)] -- Parameters, where FC is precise name span
718− [(Name, Docstring (Either Err t))] -- Param Docs
719− [(Maybe (Name, FC), Plicity, t, Maybe (Docstring (Either Err t)))] -- Fields
720− (Maybe (Name, FC)) -- Optional constructor name and location
721− (Docstring (Either Err t)) -- Constructor doc
722− SyntaxInfo -- Constructor SyntaxInfo
723− -- ^ Record declaration
724− | PClass (Docstring (Either Err t)) SyntaxInfo FC
725− [(Name, t)] -- constraints
726− Name -- class name
727− FC -- accurate location of class name
728− [(Name, FC, t)] -- parameters and precise locations
729− [(Name, Docstring (Either Err t))] -- parameter docstrings
730− [(Name, FC)] -- determining parameters and precise locations
731− [PDecl' t] -- declarations
732− (Maybe (Name, FC)) -- instance constructor name and location
733− (Docstring (Either Err t)) -- instance constructor docs
734− -- ^ Type class: arguments are documentation, syntax info, source location, constraints,
735− -- class name, class name location, parameters, method declarations, optional constructor name
736− | PInstance
737− (Docstring (Either Err t)) -- Instance docs
738− [(Name, Docstring (Either Err t))] -- Parameter docs
739− SyntaxInfo
740− FC [(Name, t)] -- constraints
741− [Name] -- parent dictionaries to search for constraints
742− Accessibility
743− FnOpts
744− Name -- class
745− FC -- precise location of class
746− [t] -- parameters
747− [(Name, t)] -- Extra names in scope in the body
748− t -- full instance type
749− (Maybe Name) -- explicit name
750− [PDecl' t]
751− -- ^ Instance declaration: arguments are documentation, syntax info, source
752− -- location, constraints, class name, parameters, full instance
753− -- type, optional explicit name, and definitions
751+ -- | Record name.
752+ | PRecord (Docstring (Either Err t)) SyntaxInfo FC DataOpts
753+ Name -- Record name
754+ FC -- Record name precise location
755+ [(Name, FC, Plicity, t)] -- Parameters, where FC is precise name span
756+ [(Name, Docstring (Either Err t))] -- Param Docs
757+ [(Maybe (Name, FC), Plicity, t, Maybe (Docstring (Either Err t)))] -- Fields
758+ (Maybe (Name, FC)) -- Optional constructor name and location
759+ (Docstring (Either Err t)) -- Constructor doc
760+ SyntaxInfo -- Constructor SyntaxInfo
761+
762+ -- | Type class: arguments are documentation, syntax info, source
763+ -- location, constraints, class name, class name location,
764+ -- parameters, method declarations, optional constructor name
765+ | PClass (Docstring (Either Err t)) SyntaxInfo FC
766+ [(Name, t)] -- constraints
767+ Name -- class name
768+ FC -- accurate location of class name
769+ [(Name, FC, t)] -- parameters and precise locations
770+ [(Name, Docstring (Either Err t))] -- parameter docstrings
771+ [(Name, FC)] -- determining parameters and precise locations
772+ [PDecl' t] -- declarations
773+ (Maybe (Name, FC)) -- instance constructor name and location
774+ (Docstring (Either Err t)) -- instance constructor docs
775+
776+ -- | Instance declaration: arguments are documentation, syntax
777+ -- info, source location, constraints, class name, parameters, full
778+ -- instance type, optional explicit name, and definitions
779+ | PInstance (Docstring (Either Err t)) -- Instance docs
780+ [(Name, Docstring (Either Err t))] -- Parameter docs
781+ SyntaxInfo
782+ FC [(Name, t)] -- constraints
783+ [Name] -- parent dictionaries to search for constraints
784+ Accessibility
785+ FnOpts
786+ Name -- class
787+ FC -- precise location of class
788+ [t] -- parameters
789+ [(Name, t)] -- Extra names in scope in the body
790+ t -- full instance type
791+ (Maybe Name) -- explicit name
792+ [PDecl' t]
754793 | PDSL Name (DSL' t) -- ^ DSL declaration
755− | PSyntax FC Syntax -- ^ Syntax definition
794+ | PSyntax FC Syntax -- ^ Syntax definition
756795 | PMutual FC [PDecl' t] -- ^ Mutual block
757− | PDirective Directive -- ^ Compiler directive.
758− | PProvider (Docstring (Either Err t)) SyntaxInfo FC FC (ProvideWhat' t) Name -- ^ Type provider. The first t is the type, the second is the term. The second FC is precise highlighting location.
759− | PTransform FC Bool t t -- ^ Source-to-source transformation rule. If
760− -- bool is True, lhs and rhs must be convertible
761− | PRunElabDecl FC t [String] -- ^ FC is decl-level, for errors, and
762− -- Strings represent the namespace
796+ | PDirective Directive -- ^ Compiler directive.
797+
798+ -- | Type provider. The first t is the type, the second is the
799+ -- term. The second FC is precise highlighting location.
800+ | PProvider (Docstring (Either Err t)) SyntaxInfo FC FC (ProvideWhat' t) Name
801+
802+ -- | Source-to-source transformation rule. If bool is True, lhs and
803+ -- rhs must be convertible.
804+ | PTransform FC Bool t t
805+
806+ -- | FC is decl-level, for errors, and Strings represent the
807+ -- namespace
808+ | PRunElabDecl FC t [String]
763809 deriving Functor
764810{-!
765811deriving instance Binary PDecl'
@@ -792,18 +838,19 @@ data RDeclInstructions = RTyDeclInstrs Name FC [PArg] Type
792838 | RClausesInstrs Name [([(Name, Term)], Term, Term)]
793839 | RAddInstance Name Name
794840 | RDatatypeDeclInstrs Name [PArg]
841+ -- | Datatype, constructors
795842 | RDatatypeDefnInstrs Name Type [(Name, [PArg], Type)]
796− -- ^ Datatype, constructors
843+
797844
798845-- | For elaborator state
799846data EState = EState {
800− case_decls :: [(Name, PDecl)],
801− delayed_elab :: [(Int, Elab' EState ())],
802− new_tyDecls :: [RDeclInstructions],
803− highlighting :: [(FC, OutputAnnotation)],
804− auto_binds :: [Name], -- names bound as auto implicits
805− implicit_warnings :: [(FC, Name)] -- Implicit warnings to report (location and global name)
806− }
847+ case_decls :: [(Name, PDecl)]
848+ , delayed_elab :: [(Int, Elab' EState ())]
849+ , new_tyDecls :: [RDeclInstructions]
850+ , highlighting :: [(FC, OutputAnnotation)]
851+ , auto_binds :: [Name] -- ^ names bound as auto implicits
852+ , implicit_warnings :: [(FC, Name)] -- ^ Implicit warnings to report (location and global name)
853+ }
807854
808855initEState :: EState
809856initEState = EState [] [] [] [] [] []
@@ -835,20 +882,23 @@ deriving instance NFData PClause'
835882!-}
836883
837884-- | Data declaration
838−data PData' t = PDatadecl { d_name :: Name, -- ^ The name of the datatype
839− d_name_fc :: FC, -- ^ The precise location of the type constructor name
840− d_tcon :: t, -- ^ Type constructor
841− d_cons :: [(Docstring (Either Err PTerm), [(Name, Docstring (Either Err PTerm))], Name, FC, t, FC, [Name])] -- ^ Constructors
842− }
843− -- ^ Data declaration
844− | PLaterdecl { d_name :: Name, d_name_fc :: FC, d_tcon :: t }
845− -- ^ "Placeholder" for data whose constructors are defined later
846− deriving Functor
885+data PData' t =
886+ -- | Data declaration
887+ PDatadecl { d_name :: Name -- ^ The name of the datatype
888+ , d_name_fc :: FC -- ^ The precise location of the type constructor name
889+ , d_tcon :: t -- ^ Type constructor
890+ , d_cons :: [(Docstring (Either Err PTerm), [(Name, Docstring (Either Err PTerm))], Name, FC, t, FC, [Name])] -- ^ Constructors
891+ }
892+ -- | "Placeholder" for data whose constructors are defined later
893+ | PLaterdecl { d_name :: Name
894+ , d_name_fc :: FC
895+ , d_tcon :: t
896+ } deriving Functor
847897
848898-- | Transform the FCs in a PData and its associated terms. The first
849−-- function transforms the general-purpose FCs, and the second transforms
850−-- those that are used for semantic source highlighting, so they can be
851−-- treated specially.
899+-- function transforms the general-purpose FCs, and the second
900+-- transforms those that are used for semantic source highlighting, so
901+-- they can be treated specially.
852902mapPDataFC :: (FC -> FC) -> (FC -> FC) -> PData -> PData
853903mapPDataFC f g (PDatadecl n nfc tycon ctors) =
854904 PDatadecl n (g nfc) (mapPTermFC f g tycon) (map ctorFC ctors)
@@ -1030,56 +1080,76 @@ updateNs ns t = mapPT updateRef t
10301080-- (map (updateDNs ns) ds)
10311081-- updateDNs ns c = c
10321082
1033−data PunInfo = IsType | IsTerm | TypeOrTerm deriving (Eq, Show, Data, Typeable)
1083+data PunInfo = IsType
1084+ | IsTerm
1085+ | TypeOrTerm
1086+ deriving (Eq, Show, Data, Typeable)
10341087
10351088-- | High level language terms
1036−data PTerm = PQuote Raw -- ^ Inclusion of a core term into the high-level language
1037− | PRef FC [FC] Name -- ^ A reference to a variable. The FC is its precise source location for highlighting. The list of FCs is a collection of additional highlighting locations.
1038− | PInferRef FC [FC] Name -- ^ A name to be defined later
1039− | PPatvar FC Name -- ^ A pattern variable
1040− | PLam FC Name FC PTerm PTerm -- ^ A lambda abstraction. Second FC is name span.
1041− | PPi Plicity Name FC PTerm PTerm -- ^ (n : t1) -> t2, where the FC is for the precise location of the variable
1042− | PLet FC Name FC PTerm PTerm PTerm -- ^ A let binding (second FC is precise name location)
1043− | PTyped PTerm PTerm -- ^ Term with explicit type
1044− | PApp FC PTerm [PArg] -- ^ e.g. IO (), List Char, length x
1045− | PWithApp FC PTerm PTerm -- ^ Application plus a 'with' argument
1046− | PAppImpl PTerm [ImplicitInfo] -- ^ Implicit argument application (introduced during elaboration only)
1047− | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
1048− | PMatchApp FC Name -- ^ Make an application by type matching
1049− | PIfThenElse FC PTerm PTerm PTerm -- ^ Conditional expressions - elaborated to an overloading of ifThenElse
1050− | PCase FC PTerm [(PTerm, PTerm)] -- ^ A case expression. Args are source location, scrutinee, and a list of pattern/RHS pairs
1051− | PTrue FC PunInfo -- ^ Unit type..?
1052− | PResolveTC FC -- ^ Solve this dictionary by type class resolution
1089+data PTerm = PQuote Raw -- ^ Inclusion of a core term into the
1090+ -- high-level language
1091+ | PRef FC [FC] Name
1092+ -- ^ A reference to a variable. The FC is its precise
1093+ -- source location for highlighting. The list of FCs is a
1094+ -- collection of additional highlighting locations.
1095+ | PInferRef FC [FC] Name -- ^ A name to be defined later
1096+ | PPatvar FC Name -- ^ A pattern variable
1097+ | PLam FC Name FC PTerm PTerm -- ^ A lambda abstraction. Second FC is name span.
1098+ | PPi Plicity Name FC PTerm PTerm -- ^ (n : t1) -> t2, where the FC is for the precise location of the variable
1099+ | PLet FC Name FC PTerm PTerm PTerm -- ^ A let binding (second FC is precise name location)
1100+ | PTyped PTerm PTerm -- ^ Term with explicit type
1101+ | PApp FC PTerm [PArg] -- ^ e.g. IO (), List Char, length x
1102+ | PWithApp FC PTerm PTerm -- ^ Application plus a 'with' argument
1103+ | PAppImpl PTerm [ImplicitInfo] -- ^ Implicit argument application (introduced during elaboration only)
1104+ | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
1105+ | PMatchApp FC Name -- ^ Make an application by type matching
1106+ | PIfThenElse FC PTerm PTerm PTerm -- ^ Conditional expressions - elaborated to an overloading of ifThenElse
1107+ | PCase FC PTerm [(PTerm, PTerm)] -- ^ A case expression. Args are source location, scrutinee, and a list of pattern/RHS pairs
1108+ | PTrue FC PunInfo -- ^ Unit type..?
1109+ | PResolveTC FC -- ^ Solve this dictionary by type class resolution
10531110 | PRewrite FC (Maybe Name) PTerm PTerm (Maybe PTerm)
1054− -- ^ "rewrite" syntax, with optional rewriting function
1055− -- and optional result type
1056− | PPair FC [FC] PunInfo PTerm PTerm -- ^ A pair (a, b) and whether it's a product type or a pair (solved by elaboration). The list of FCs is its punctuation.
1057− | PDPair FC [FC] PunInfo PTerm PTerm PTerm -- ^ A dependent pair (tm : a ** b) and whether it's a sigma type or a pair that inhabits one (solved by elaboration). The [FC] is its punctuation.
1058− | PAs FC Name PTerm -- ^ @-pattern, valid LHS only
1111+ -- ^ "rewrite" syntax, with optional rewriting function and
1112+ -- optional result type
1113+ | PPair FC [FC] PunInfo PTerm PTerm
1114+ -- ^ A pair (a, b) and whether it's a product type or a
1115+ -- pair (solved by elaboration). The list of FCs is its
1116+ -- punctuation.
1117+ | PDPair FC [FC] PunInfo PTerm PTerm PTerm
1118+ -- ^ A dependent pair (tm : a ** b) and whether it's a
1119+ -- sigma type or a pair that inhabits one (solved by
1120+ -- elaboration). The [FC] is its punctuation.
1121+ | PAs FC Name PTerm -- ^ @-pattern, valid LHS only
10591122 | PAlternative [(Name, Name)] PAltType [PTerm] -- ^ (| A, B, C|). Includes unapplied unique name mappings for mkUniqueNames.
1060− | PHidden PTerm -- ^ Irrelevant or hidden pattern
1061− | PType FC -- ^ 'Type' type
1062− | PUniverse Universe -- ^ Some universe
1063− | PGoal FC PTerm Name PTerm -- ^ quoteGoal, used for %reflection functions
1064− | PConstant FC Const -- ^ Builtin types
1065− | Placeholder -- ^ Underscore
1066− | PDoBlock [PDo] -- ^ Do notation
1067− | PIdiom FC PTerm -- ^ Idiom brackets
1123+ | PHidden PTerm -- ^ Irrelevant or hidden pattern
1124+ | PType FC -- ^ 'Type' type
1125+ | PUniverse Universe -- ^ Some universe
1126+ | PGoal FC PTerm Name PTerm -- ^ quoteGoal, used for %reflection functions
1127+ | PConstant FC Const -- ^ Builtin types
1128+ | Placeholder -- ^ Underscore
1129+ | PDoBlock [PDo] -- ^ Do notation
1130+ | PIdiom FC PTerm -- ^ Idiom brackets
10681131 | PReturn FC
1069− | PMetavar FC Name -- ^ A metavariable, ?name, and its precise location
1070− | PProof [PTactic] -- ^ Proof script
1071− | PTactics [PTactic] -- ^ As PProof, but no auto solving
1072− | PElabError Err -- ^ Error to report on elaboration
1073− | PImpossible -- ^ Special case for declaring when an LHS can't typecheck
1074− | PCoerced PTerm -- ^ To mark a coerced argument, so as not to coerce twice
1075− | PDisamb [[T.Text]] PTerm -- ^ Preferences for explicit namespaces
1076− | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
1077− | PNoImplicits PTerm -- ^ never run implicit converions on the term
1078− | PQuasiquote PTerm (Maybe PTerm) -- ^ `(Term [: Term])
1079− | PUnquote PTerm -- ^ ~Term
1080− | PQuoteName Name Bool FC -- ^ `{n} where the FC is the precise highlighting for the name in particular. If the Bool is False, then it's `{{n}} and the name won't be resolved.
1081− | PRunElab FC PTerm [String] -- ^ %runElab tm - New-style proof script. Args are location, script, enclosing namespace.
1082− | PConstSugar FC PTerm -- ^ A desugared constant. The FC is a precise source location that will be used to highlight it later.
1132+ | PMetavar FC Name -- ^ A metavariable, ?name, and its precise location
1133+ | PProof [PTactic] -- ^ Proof script
1134+ | PTactics [PTactic] -- ^ As PProof, but no auto solving
1135+ | PElabError Err -- ^ Error to report on elaboration
1136+ | PImpossible -- ^ Special case for declaring when an LHS can't typecheck
1137+ | PCoerced PTerm -- ^ To mark a coerced argument, so as not to coerce twice
1138+ | PDisamb [[T.Text]] PTerm -- ^ Preferences for explicit namespaces
1139+ | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
1140+ | PNoImplicits PTerm -- ^ never run implicit converions on the term
1141+ | PQuasiquote PTerm (Maybe PTerm) -- ^ `(Term [: Term])
1142+ | PUnquote PTerm -- ^ ~Term
1143+ | PQuoteName Name Bool FC
1144+ -- ^ `{n} where the FC is the precise highlighting for
1145+ -- the name in particular. If the Bool is False, then
1146+ -- it's `{{n}} and the name won't be resolved.
1147+ | PRunElab FC PTerm [String]
1148+ -- ^ %runElab tm - New-style proof script. Args are
1149+ -- location, script, enclosing namespace.
1150+ | PConstSugar FC PTerm
1151+ -- ^ A desugared constant. The FC is a precise source
1152+ -- location that will be used to highlight it later.
10831153 deriving (Eq, Data, Typeable)
10841154
10851155data PAltType = ExactlyOne Bool -- ^ flag sets whether delay is allowed
@@ -1249,9 +1319,9 @@ instance Sized a => Sized (PTactic' a) where
12491319type PTactic = PTactic' PTerm
12501320
12511321data PDo' t = DoExp FC t
1252− | DoBind FC Name FC t -- ^ second FC is precise name location
1322+ | DoBind FC Name FC t -- ^ second FC is precise name location
12531323 | DoBindP FC t t [(t,t)]
1254− | DoLet FC Name FC t t -- ^ second FC is precise name location
1324+ | DoLet FC Name FC t t -- ^ second FC is precise name location
12551325 | DoLetP FC t t
12561326 deriving (Eq, Functor, Data, Typeable)
12571327{-!
@@ -1262,9 +1332,9 @@ deriving instance NFData PDo'
12621332instance Sized a => Sized (PDo' a) where
12631333 size (DoExp fc t) = 1 + size fc + size t
12641334 size (DoBind fc nm nfc t) = 1 + size fc + size nm + size nfc + size t
1265− size (DoBindP fc l r alts) = 1 + size fc + size l + size r + size alts
1266− size (DoLet fc nm nfc l r) = 1 + size fc + size nm + size l + size r
1267− size (DoLetP fc l r) = 1 + size fc + size l + size r
1335+ size (DoBindP fc l r alts) = 1 + size fc + size l + size r + size alts
1336+ size (DoLet fc nm nfc l r) = 1 + size fc + size nm + size l + size r
1337+ size (DoLetP fc l r) = 1 + size fc + size l + size r
12681338
12691339type PDo = PDo' PTerm
12701340
@@ -1272,33 +1342,40 @@ type PDo = PDo' PTerm
12721342-- things early which will help give a more concrete type to other
12731343-- variables, e.g. a before (interpTy a).
12741344
1275−data PArg' t = PImp { priority :: Int,
1276− machine_inf :: Bool, -- true if the machine inferred it
1277− argopts :: [ArgOpt],
1278− pname :: Name,
1279− getTm :: t }
1280− | PExp { priority :: Int,
1281− argopts :: [ArgOpt],
1282− pname :: Name,
1283− getTm :: t }
1284− | PConstraint { priority :: Int,
1285− argopts :: [ArgOpt],
1286− pname :: Name,
1287− getTm :: t }
1288− | PTacImplicit { priority :: Int,
1289− argopts :: [ArgOpt],
1290− pname :: Name,
1291− getScript :: t,
1292− getTm :: t }
1293− deriving (Show, Eq, Functor, Data, Typeable)
1294−
1295−data ArgOpt = AlwaysShow | HideDisplay | InaccessibleArg | UnknownImp
1296− deriving (Show, Eq, Data, Typeable)
1345+data PArg' t = PImp { priority :: Int
1346+ , machine_inf :: Bool -- ^ true if the machine inferred it
1347+ , argopts :: [ArgOpt]
1348+ , pname :: Name
1349+ , getTm :: t
1350+ }
1351+ | PExp { priority :: Int
1352+ , argopts :: [ArgOpt]
1353+ , pname :: Name
1354+ , getTm :: t
1355+ }
1356+ | PConstraint { priority :: Int
1357+ , argopts :: [ArgOpt]
1358+ , pname :: Name
1359+ , getTm :: t
1360+ }
1361+ | PTacImplicit { priority :: Int
1362+ , argopts :: [ArgOpt]
1363+ , pname :: Name
1364+ , getScript :: t
1365+ , getTm :: t
1366+ }
1367+ deriving (Show, Eq, Functor, Data, Typeable)
1368+
1369+data ArgOpt = AlwaysShow
1370+ | HideDisplay
1371+ | InaccessibleArg
1372+ | UnknownImp
1373+ deriving (Show, Eq, Data, Typeable)
12971374
12981375instance Sized a => Sized (PArg' a) where
12991376 size (PImp p _ l nm trm) = 1 + size nm + size trm
13001377 size (PExp p l nm trm) = 1 + size nm + size trm
1301− size (PConstraint p l nm trm) = 1 + size nm +size nm + size trm
1378+ size (PConstraint p l nm trm) = 1 + size nm + size nm + size trm
13021379 size (PTacImplicit p l nm scr trm) = 1 + size nm + size scr + size trm
13031380
13041381{-!
@@ -1375,28 +1452,30 @@ highestFC (PAppImpl t _) = highestFC t
13751452
13761453-- Type class data
13771454
1378−data ClassInfo = CI { instanceCtorName :: Name,
1379− class_methods :: [(Name, (Bool, FnOpts, PTerm))], -- flag whether it's a "data" method
1380− class_defaults :: [(Name, (Name, PDecl))], -- method name -> default impl
1381− class_default_superclasses :: [PDecl],
1382− class_params :: [Name],
1383− class_instances :: [(Name, Bool)], -- the Bool is whether to include in instance search, so named instances are excluded
1384− class_determiners :: [Int] }
1385− deriving Show
1455+data ClassInfo = CI {
1456+ instanceCtorName :: Name
1457+ , class_methods :: [(Name, (Bool, FnOpts, PTerm))] -- ^ flag whether it's a "data" method
1458+ , class_defaults :: [(Name, (Name, PDecl))] -- ^ method name -> default impl
1459+ , class_default_superclasses :: [PDecl]
1460+ , class_params :: [Name]
1461+ , class_instances :: [(Name, Bool)] -- ^ the Bool is whether to include in instance search, so named instances are excluded
1462+ , class_determiners :: [Int]
1463+ } deriving Show
13861464{-!
13871465deriving instance Binary ClassInfo
13881466deriving instance NFData ClassInfo
13891467!-}
13901468
13911469-- Record data
1392−data RecordInfo = RI { record_parameters :: [(Name,PTerm)],
1393− record_constructor :: Name,
1394− record_projections :: [Name] }
1395− deriving Show
1470+data RecordInfo = RI {
1471+ record_parameters :: [(Name,PTerm)]
1472+ , record_constructor :: Name
1473+ , record_projections :: [Name]
1474+ } deriving Show
13961475
13971476-- Type inference data
13981477
1399−data TIData = TIPartial -- ^ a function with a partially defined type
1478+data TIData = TIPartial -- ^ a function with a partially defined type
14001479 | TISolution [Term] -- ^ possible solutions to a metavariable in a type
14011480 deriving Show
14021481
@@ -1408,27 +1487,28 @@ deriving instance Binary FnInfo
14081487deriving instance NFData FnInfo
14091488!-}
14101489
1411−data OptInfo = Optimise { inaccessible :: [(Int,Name)], -- includes names for error reporting
1412− detaggable :: Bool }
1413− deriving Show
1490+data OptInfo = Optimise {
1491+ inaccessible :: [(Int,Name)] -- includes names for error reporting
1492+ , detaggable :: Bool
1493+ } deriving Show
14141494{-!
14151495deriving instance Binary OptInfo
14161496deriving instance NFData OptInfo
14171497!-}
14181498
14191499-- | Syntactic sugar info
1420−data DSL' t = DSL { dsl_bind :: t,
1421− dsl_return :: t,
1422− dsl_apply :: t,
1423− dsl_pure :: t,
1424− dsl_var :: Maybe t,
1425− index_first :: Maybe t,
1426− index_next :: Maybe t,
1427− dsl_lambda :: Maybe t,
1428− dsl_let :: Maybe t,
1429− dsl_pi :: Maybe t
1430− }
1431− deriving (Show, Functor)
1500+data DSL' t = DSL {
1501+ dsl_bind :: t
1502+ , dsl_return :: t
1503+ , dsl_apply :: t
1504+ , dsl_pure :: t
1505+ , dsl_var :: Maybe t
1506+ , index_first :: Maybe t
1507+ , index_next :: Maybe t
1508+ , dsl_lambda :: Maybe t
1509+ , dsl_let :: Maybe t
1510+ , dsl_pi :: Maybe t
1511+ } deriving (Show, Functor)
14321512{-!
14331513deriving instance Binary DSL'
14341514deriving instance NFData DSL'
@@ -1436,7 +1516,9 @@ deriving instance NFData DSL'
14361516
14371517type DSL = DSL' PTerm
14381518
1439−data SynContext = PatternSyntax | TermSyntax | AnySyntax
1519+data SynContext = PatternSyntax
1520+ | TermSyntax
1521+ | AnySyntax
14401522 deriving Show
14411523{-!
14421524deriving instance Binary SynContext
@@ -1536,24 +1618,25 @@ deriving instance Binary Using
15361618deriving instance NFData Using
15371619!-}
15381620
1539−data SyntaxInfo = Syn { using :: [Using],
1540− syn_params :: [(Name, PTerm)],
1541− syn_namespace :: [String],
1542− no_imp :: [Name],
1543− imp_methods :: [Name], -- class methods. When expanding
1544− -- implicits, these should be expanded even under
1545− -- binders
1546− decoration :: Name -> Name,
1547− inPattern :: Bool,
1548− implicitAllowed :: Bool,
1549− constraintAllowed :: Bool,
1550− maxline :: Maybe Int,
1551− mut_nesting :: Int,
1552− dsl_info :: DSL,
1553− syn_in_quasiquote :: Int,
1554− syn_toplevel :: Bool,
1555− withAppAllowed :: Bool }
1556− deriving Show
1621+data SyntaxInfo = Syn {
1622+ using :: [Using]
1623+ , syn_params :: [(Name, PTerm)]
1624+ , syn_namespace :: [String]
1625+ , no_imp :: [Name]
1626+ , imp_methods :: [Name]
1627+ -- ^ class methods. When expanding implicits, these should be
1628+ -- expanded even under binders
1629+ , decoration :: Name -> Name
1630+ , inPattern :: Bool
1631+ , implicitAllowed :: Bool
1632+ , constraintAllowed :: Bool
1633+ , maxline :: Maybe Int
1634+ , mut_nesting :: Int
1635+ , dsl_info :: DSL
1636+ , syn_in_quasiquote :: Int
1637+ , syn_toplevel :: Bool
1638+ , withAppAllowed :: Bool
1639+ } deriving Show
15571640{-!
15581641deriving instance NFData SyntaxInfo
15591642deriving instance Binary SyntaxInfo
@@ -1693,9 +1776,9 @@ instance Show PData where
16931776instance Pretty PTerm OutputAnnotation where
16941777 pretty = prettyImp defaultPPOption
16951778
1696−-- | Colourise annotations according to an Idris state. It ignores the names
1697−-- in the annotation, as there's no good way to show extended information on a
1698−-- terminal.
1779+-- | Colourise annotations according to an Idris state. It ignores the
1780+-- names in the annotation, as there's no good way to show extended
1781+-- information on a terminal.
16991782annotationColour :: IState -> OutputAnnotation -> Maybe IdrisColour
17001783annotationColour ist _ | not (idris_colourRepl ist) = Nothing
17011784annotationColour ist (AnnConst c) =
@@ -1724,8 +1807,8 @@ annotationColour ist (AnnTextFmt fmt) = Just (colour fmt)
17241807annotationColour ist _ = Nothing
17251808
17261809
1727−-- | Colourise annotations according to an Idris state. It ignores the names
1728−-- in the annotation, as there's no good way to show extended
1810+-- | Colourise annotations according to an Idris state. It ignores the
1811+-- names in the annotation, as there's no good way to show extended
17291812-- information on a terminal. Note that strings produced this way will
17301813-- not be coloured on Windows, so the use of the colour rendering
17311814-- functions in Idris.Output is to be preferred.
@@ -1735,9 +1818,10 @@ consoleDecorate ist ann = maybe id colourise (annotationColour ist ann)
17351818isPostulateName :: Name -> IState -> Bool
17361819isPostulateName n ist = S.member n (idris_postulates ist)
17371820
1738−-- | Pretty-print a high-level closed Idris term with no information about precedence/associativity
1739−prettyImp :: PPOption -- ^^ pretty printing options
1740− -> PTerm -- ^^ the term to pretty-print
1821+-- | Pretty-print a high-level closed Idris term with no information
1822+-- about precedence/associativity
1823+prettyImp :: PPOption -- ^ pretty printing options
1824+ -> PTerm -- ^ the term to pretty-print
17411825 -> Doc OutputAnnotation
17421826prettyImp impl = pprintPTerm impl [] [] []
17431827
@@ -1747,12 +1831,13 @@ prettyImp impl = pprintPTerm impl [] [] []
17471831prettyIst :: IState -> PTerm -> Doc OutputAnnotation
17481832prettyIst ist = pprintPTerm (ppOptionIst ist) [] [] (idris_infixes ist)
17491833
1750−-- | Pretty-print a high-level Idris term in some bindings context with infix info
1751−pprintPTerm :: PPOption -- ^^ pretty printing options
1752− -> [(Name, Bool)] -- ^^ the currently-bound names and whether they are implicit
1753− -> [Name] -- ^^ names to always show in pi, even if not used
1754− -> [FixDecl] -- ^^ Fixity declarations
1755− -> PTerm -- ^^ the term to pretty-print
1834+-- | Pretty-print a high-level Idris term in some bindings context
1835+-- with infix info.
1836+pprintPTerm :: PPOption -- ^ pretty printing options
1837+ -> [(Name, Bool)] -- ^ the currently-bound names and whether they are implicit
1838+ -> [Name] -- ^ names to always show in pi, even if not used
1839+ -> [FixDecl] -- ^ Fixity declarations
1840+ -> PTerm -- ^ the term to pretty-print
17561841 -> Doc OutputAnnotation
17571842pprintPTerm ppo bnd docArgs infixes = prettySe (ppopt_depth ppo) startPrec bnd
17581843 where
@@ -2125,8 +2210,8 @@ basename :: Name -> Name
21252210basename (NS n _) = basename n
21262211basename n = n
21272212
2128−-- | Determine whether a name was the one inserted for a hole or
2129−-- guess by the delaborator
2213+-- | Determine whether a name was the one inserted for a hole or guess
2214+-- by the delaborator
21302215isHoleName :: Name -> Bool
21312216isHoleName (UN n) = n == T.pack "[__]"
21322217isHoleName _ = False
@@ -2136,12 +2221,11 @@ containsHole :: PTerm -> Bool
21362221containsHole pterm = or [isHoleName n | PRef _ _ n <- take 1000 $ universe pterm]
21372222
21382223-- | Pretty-printer helper for names that attaches the correct annotations
2139−prettyName
2140− :: Bool -- ^^ whether the name should be parenthesised if it is an infix operator
2141− -> Bool -- ^^ whether to show namespaces
2142− -> [(Name, Bool)] -- ^^ the current bound variables and whether they are implicit
2143− -> Name -- ^^ the name to pprint
2144− -> Doc OutputAnnotation
2224+prettyName :: Bool -- ^ whether the name should be parenthesised if it is an infix operator
2225+ -> Bool -- ^ whether to show namespaces
2226+ -> [(Name, Bool)] -- ^ the current bound variables and whether they are implicit
2227+ -> Name -- ^ the name to pprint
2228+ -> Doc OutputAnnotation
21452229prettyName infixParen showNS bnd n
21462230 | (MN _ s) <- n, isPrefixOf "_" $ T.unpack s = text "_"
21472231 | (UN n') <- n, T.unpack n' == "_" = text "_"
@@ -2228,11 +2312,11 @@ getAll = map getTm
22282312
22292313
22302314-- | Show Idris name
2231−showName :: Maybe IState -- ^^ the Idris state, for information about names and colours
2232− -> [(Name, Bool)] -- ^^ the bound variables and whether they're implicit
2233− -> PPOption -- ^^ pretty printing options
2234− -> Bool -- ^^ whether to colourise
2235− -> Name -- ^^ the term to show
2315+showName :: Maybe IState -- ^ the Idris state, for information about names and colours
2316+ -> [(Name, Bool)] -- ^ the bound variables and whether they're implicit
2317+ -> PPOption -- ^ pretty printing options
2318+ -> Bool -- ^ whether to colourise
2319+ -> Name -- ^ the term to show
22362320 -> String
22372321showName ist bnd ppo colour n = case ist of
22382322 Just i -> if colour then colourise n (idris_colourTheme i) else showbasic n
@@ -2256,8 +2340,8 @@ showName ist bnd ppo colour n = case ist of
22562340 -- (like error messages). Thus, unknown vars are colourised as implicits.
22572341 | otherwise -> colouriseImplicit t name
22582342
2259−showTm :: IState -- ^^ the Idris state, for information about identifiers and colours
2260− -> PTerm -- ^^ the term to show
2343+showTm :: IState -- ^ the Idris state, for information about identifiers and colours
2344+ -> PTerm -- ^ the term to show
22612345 -> String
22622346showTm ist = displayDecorated (consoleDecorate ist) .
22632347 renderPretty 0.8 100000 .
src/Idris/CaseSplit.hs+11−11
@@ -50,11 +50,11 @@ Always take the "more specific" argument when there is a discrepancy, i.e.
5050names over '_', patterns over names, etc.
5151-}
5252
53−-- Given a variable to split, and a term application, return a list of
54−-- variable updates, paired with a flag to say whether the given update
55−-- typechecks (False = impossible)
56−-- if the flag is 'False' the splits should be output with the 'impossible'
57−-- flag, otherwise they should be output as normal
53+-- | Given a variable to split, and a term application, return a list
54+-- of variable updates, paired with a flag to say whether the given
55+-- update typechecks (False = impossible) if the flag is 'False' the
56+-- splits should be output with the 'impossible' flag, otherwise they
57+-- should be output as normal
5858split :: Name -> PTerm -> Idris (Bool, [[(Name, PTerm)]])
5959split n t'
6060 = do ist <- getIState
@@ -170,8 +170,8 @@ mergePat ist orig new t =
170170 put (ms { namemap = ((n', n) : namemap ms) })
171171 addNameMap _ = return ()
172172
173−-- If any names are unified, make sure they stay unified. Always prefer
174−-- user provided name (first pattern)
173+-- | If any names are unified, make sure they stay unified. Always
174+-- prefer user provided name (first pattern)
175175mergePat' ist (PPatvar fc n) new t
176176 = mergePat' ist (PRef fc [] n) new t
177177mergePat' ist old (PPatvar fc n) t
@@ -240,7 +240,7 @@ elabNewPat t = idrisCatch (do (tm, ty) <- elabVal recinfo ELHS t
240240 i <- getIState
241241 return (True, delab i tm))
242242 (\e -> do i <- getIState
243− logElab 5 $ "Not a valid split:\n" ++ showTmImpls t ++ "\n"
243+ logElab 5 $ "Not a valid split:\n" ++ showTmImpls t ++ "\n"
244244 ++ pshow i e
245245 return (False, t))
246246
@@ -352,7 +352,7 @@ replaceSplits l ups impossible
352352 updatePat start n tm (c:rest) = c : updatePat (not ((isAlphaNum c) || c == '_')) n tm rest
353353
354354 addBrackets tm | ' ' `elem` tm
355− , not (isPrefixOf "(" tm && isSuffixOf ")" tm)
355+ , not (isPrefixOf "(" tm && isSuffixOf ")" tm)
356356 = "(" ++ tm ++ ")"
357357 | otherwise = tm
358358
@@ -373,14 +373,14 @@ nameRoot acc nm =
373373
374374-- Show a name for use in pattern definitions on the lhs
375375showLHSName :: Name -> String
376−showLHSName n = let fn = show n in
376+showLHSName n = let fn = show n in
377377 if any (flip elem opChars) fn
378378 then "(" ++ fn ++ ")"
379379 else fn
380380
381381-- Show a name for the purpose of generating a metavariable name on the rhs
382382showRHSName :: Name -> String
383−showRHSName n = let fn = show n in
383+showRHSName n = let fn = show n in
384384 if any (flip elem opChars) fn
385385 then "op"
386386 else fn
src/Idris/Chaser.hs+16−15
@@ -28,10 +28,9 @@ latest :: UTCTime -> [ModuleTree] -> UTCTime
2828latest tm [] = tm
2929latest tm (m : ms) = latest (max tm (mod_time m)) (ms ++ mod_deps m)
3030
31−-- Given a module tree, return the list of files to be loaded. If any
32−-- module has a descendent which needs reloading, return its source, otherwise
33−-- return the IBC
34−
31+-- | Given a module tree, return the list of files to be loaded. If
32+-- any module has a descendent which needs reloading, return its
33+-- source, otherwise return the IBC
3534getModuleFiles :: [ModuleTree] -> [IFileType]
3635getModuleFiles ts = nub $ execState (modList ts) [] where
3736 modList :: [ModuleTree] -> State [IFileType] ()
@@ -66,7 +65,7 @@ getModuleFiles ts = nub $ execState (modList ts) [] where
6665 then getSrc x : updateToSrc path xs
6766 else x : updateToSrc path xs
6867
69−-- Strip quotes and the backslash escapes that Haskeline adds
68+-- | Strip quotes and the backslash escapes that Haskeline adds
7069extractFileName :: String -> String
7170extractFileName ('"':xs) = takeWhile (/= '"') xs
7271extractFileName ('\'':xs) = takeWhile (/= '\'') xs
@@ -80,10 +79,11 @@ getIModTime (IBC i _) = getModificationTime i
8079getIModTime (IDR i) = getModificationTime i
8180getIModTime (LIDR i) = getModificationTime i
8281
83−getImports :: [(FilePath, [ImportInfo])] -> [FilePath] ->
84− Idris [(FilePath, [ImportInfo])]
82+getImports :: [(FilePath, [ImportInfo])]
83+ -> [FilePath]
84+ -> Idris [(FilePath, [ImportInfo])]
8585getImports acc [] = return acc
86−getImports acc (f : fs) = do
86+getImports acc (f : fs) = do
8787 i <- getIState
8888 let file = extractFileName f
8989 ibcsd <- valIBCSubDir i
@@ -97,7 +97,7 @@ getImports acc (f : fs) = do
9797 exist <- runIO $ doesFileExist parsef
9898 if exist then do
9999 src_in <- runIO $ readSource parsef
100− src <- if lit fp then tclift $ unlit parsef src_in
100+ src <- if lit fp then tclift $ unlit parsef src_in
101101 else return src_in
102102 (_, _, modules, _) <- parseImports parsef src
103103 clearParserWarnings
@@ -113,18 +113,19 @@ getImports acc (f : fs) = do
113113 fname (LIDR fn) = fn
114114 fname (IBC _ src) = fname src
115115
116−buildTree :: [FilePath] -> -- already guaranteed built
117− [(FilePath, [ImportInfo])] -> -- import lists (don't reparse)
118− FilePath -> Idris [ModuleTree]
116+buildTree :: [FilePath] -- ^ already guaranteed built
117+ -> [(FilePath, [ImportInfo])] -- ^ import lists (don't reparse)
118+ -> FilePath
119+ -> Idris [ModuleTree]
119120buildTree built importlists fp = evalStateT (btree [] fp) []
120121 where
121− addFile :: FilePath -> [ModuleTree] ->
122+ addFile :: FilePath -> [ModuleTree] ->
122123 StateT [(FilePath, [ModuleTree])] Idris [ModuleTree]
123124 addFile f m = do fs <- get
124125 put ((f, m) : fs)
125126 return m
126127
127− btree :: [FilePath] -> FilePath ->
128+ btree :: [FilePath] -> FilePath ->
128129 StateT [(FilePath, [ModuleTree])] Idris [ModuleTree]
129130 btree stk f =
130131 do i <- lift getIState
@@ -137,7 +138,7 @@ buildTree built importlists fp = evalStateT (btree [] fp) []
137138 mt <- lift $ runIO $ getIModTime fp
138139 if (file `elem` built)
139140 then return [MTree fp False mt []]
140− else if file `elem` stk then
141+ else if file `elem` stk then
141142 do lift $ tclift $ tfail
142143 (Msg $ "Cycle detected in imports: "
143144 ++ showSep " -> " (reverse (file : stk)))
src/Idris/Coverage.hs+22−25
@@ -101,7 +101,7 @@ genClauses fc n xs given
101101 -- anything based on earlier values
102102 genPH :: IState -> Type -> [Bool]
103103 genPH ist (Bind n (Pi _ ty _) sc) = notConcrete ist ty : genPH ist sc
104− genPH ist ty = []
104+ genPH ist ty = []
105105
106106 notConcrete ist t | (P _ n _, args) <- unApply t,
107107 not (isConName n (tt_ctxt ist)) = True
@@ -315,9 +315,8 @@ genAll i (addPH, args)
315315upd :: t -> PArg' t -> PArg' t
316316upd p' p = p { getTm = p' }
317317
318−-- Check whether function and all descendants cover all cases (partial is
319−-- okay, as long as it's due to recursion)
320−
318+-- | Check whether function and all descendants cover all cases
319+-- (partial is okay, as long as it's due to recursion)
321320checkAllCovering :: FC -> [Name] -> Name -> Name -> Idris ()
322321checkAllCovering fc done top n | not (n `elem` done)
323322 = do i <- get
@@ -334,10 +333,10 @@ checkAllCovering fc done top n | not (n `elem` done)
334333 x -> return () -- stop if total
335334checkAllCovering _ _ _ _ = return ()
336335
337−-- | Check if, in a given group of type declarations mut_ns,
338−-- the constructor cn : ty is strictly positive,
339−-- and update the context accordingly
340−checkPositive :: [Name] -- ^ the group of type declarations
336+-- | Check if, in a given group of type declarations mut_ns, the
337+-- constructor cn : ty is strictly positive, and update the context
338+-- accordingly
339+checkPositive :: [Name] -- ^ the group of type declarations
341340 -> (Name, Type) -- ^ the constructor
342341 -> Idris Totality
343342checkPositive mut_ns (cn, ty')
@@ -368,8 +367,8 @@ checkPositive mut_ns (cn, ty')
368367 noRec arg = all (\x -> x `notElem` mut_ns) (allTTNames arg)
369368
370369
371−-- | Calculate the totality of a function from its patterns.
372−-- Either follow the size change graph (if inductive) or check for
370+-- | Calculate the totality of a function from its patterns. Either
371+-- follow the size change graph (if inductive) or check for
373372-- productivity (if coinductive)
374373calcTotality :: FC -> Name -> [([Name], Term, Term)] -> Idris Totality
375374calcTotality fc n pats
@@ -508,7 +507,7 @@ buildSCG' ist topfn pats args = nub $ concatMap scgPat pats where
508507 scgPat (lhs, rhs) = let lhs' = delazy lhs
509508 rhs' = delazy rhs
510509 (f, pargs) = unApply (dePat lhs') in
511− findCalls [] Toplevel (dePat rhs') (patvars lhs')
510+ findCalls [] Toplevel (dePat rhs') (patvars lhs')
512511 (zip pargs [0..])
513512
514513 findCalls cases Delayed ap@(P _ n _) pvs args
@@ -526,7 +525,7 @@ buildSCG' ist topfn pats args = nub $ concatMap scgPat pats where
526525 -- check under guarded constructors.
527526 | (P _ (UN del) _, [_,_,arg]) <- unApply ap,
528527 Guarded <- guarded,
529− del == txt "Delay"
528+ del == txt "Delay"
530529 = findCalls cases Delayed arg pvs pargs
531530 | (P _ n _, args) <- unApply ap,
532531 Delayed <- guarded,
@@ -536,7 +535,7 @@ buildSCG' ist topfn pats args = nub $ concatMap scgPat pats where
536535 | (P _ n _, args) <- unApply ap,
537536 Delayed <- guarded,
538537 isConName n (tt_ctxt ist)
539− = -- Still under a 'Delay' and constructor guarded, so check
538+ = -- Still under a 'Delay' and constructor guarded, so check
540539 -- just the arguments to the constructor, remaining Delayed
541540 concatMap (\x -> findCalls cases guarded x pvs pargs) args
542541 | (P _ n _, args) <- unApply ap,
@@ -551,7 +550,7 @@ buildSCG' ist topfn pats args = nub $ concatMap scgPat pats where
551550 then findCallsCase (n : cases) guarded n args pvs pargs
552551 else []
553552 | (P _ n _, args) <- unApply ap
554− -- Ordinary call, not under a delay.
553+ -- Ordinary call, not under a delay.
555554 -- If n is a constructor, set 'args' as Guarded
556555 = let nguarded = case guarded of
557556 Unguarded -> Unguarded
@@ -579,20 +578,20 @@ buildSCG' ist topfn pats args = nub $ concatMap scgPat pats where
579578 -- are okay for building the size change
580579 findCallsCase cases guarded n args pvs pargs
581580 = case lookupDefExact n (tt_ctxt ist) of
582− Just (CaseOp _ _ _ pats _ cd) ->
581+ Just (CaseOp _ _ _ pats _ cd) ->
583582 concatMap (fccPat cases pvs pargs args guarded) (rights pats)
584583 Nothing -> []
585584
586− fccPat cases pvs pargs args g (lhs, rhs)
585+ fccPat cases pvs pargs args g (lhs, rhs)
587586 = let lhs' = delazy lhs
588587 rhs' = delazy rhs
589− (f, pargs_case) = unApply (dePat lhs')
588+ (f, pargs_case) = unApply (dePat lhs')
590589 -- pargs is a pair of a term, and the argument position that
591590 -- term appears in. If any of the arguments to the case block
592591 -- are also on the lhs, we also want those patterns to appear
593592 -- in the parg list so that we'll spot patterns which are
594593 -- smaller than then
595− newpargs = newPArg args pargs
594+ newpargs = newPArg args pargs
596595 -- Now need to update the rhs of the case with the names in the
597596 -- outer definition: In rhs', wherever we see what's in pargs_case,
598597 -- replace it with the corresponding thing in pargs
@@ -602,11 +601,11 @@ buildSCG' ist topfn pats args = nub $ concatMap scgPat pats where
602601 findCalls cases g newrhs pvs pargs'
603602 where
604603 doCaseSubs [] tm = tm
605− doCaseSubs ((x, x') : cs) tm
604+ doCaseSubs ((x, x') : cs) tm
606605 = doCaseSubs (subIn x x' cs) (substTerm x x' tm)
607−
606+
608607 subIn x x' [] = []
609− subIn x x' ((l, r) : cs)
608+ subIn x x' ((l, r) : cs)
610609 = (substTerm x x' l, substTerm x x' r) : subIn x x' cs
611610
612611 addPArg (Just (t, i) : ts) (t' : ts') = (t', i) : addPArg ts ts'
@@ -639,7 +638,7 @@ buildSCG' ist topfn pats args = nub $ concatMap scgPat pats where
639638 as == txt "assert_smaller" && arg == p
640639 = Just (i, Smaller)
641640 | smaller Nothing a (p, Nothing) = Just (i, Smaller)
642− | otherwise = checkSize a ps
641+ | otherwise = checkSize a ps
643642 checkSize a [] = Nothing
644643
645644 -- the smaller thing we find must be defined in the same group of mutally
@@ -692,7 +691,7 @@ checkSizeChange n = do
692691 -- (Unchecked is okay as we'll spot problems here)
693692 let tot = map (checkMP ist n (getArity ist n)) ms
694693 logCoverage 4 $ "Generated " ++ show (length tot) ++ " paths"
695− logCoverage 5 $ "Paths for " ++ show n ++ " yield " ++
694+ logCoverage 5 $ "Paths for " ++ show n ++ " yield " ++
696695 (showSep "\n" (map show (zip ms tot)))
697696 return (noPartial tot)
698697 [] -> do logCoverage 5 $ "No paths for " ++ show n
@@ -826,5 +825,3 @@ totalityCheckBlock = do
826825 mapM_ buildSCG (idris_totcheck ist)
827826 mapM_ checkDeclTotality (idris_totcheck ist)
828827 clear_totcheck
829−
830−
src/Idris/DataOpts.hs+1−1
@@ -87,7 +87,7 @@ instance Optimisable (TT Name) where
8787 applyOpts (Proj t i) = Proj <$> applyOpts t <*> pure i
8888 applyOpts t = return t
8989
90−-- Need to saturate arguments first to ensure that optimisation happens uniformly
90+-- | Need to saturate arguments first to ensure that optimisation happens uniformly
9191applyDataOptRT :: Name -> Int -> Int -> Bool -> [Term] -> Term
9292applyDataOptRT n tag arity uniq args
9393 | length args == arity = doOpts n args
src/Idris/Elab/Class.hs+24−18
@@ -54,14 +54,20 @@ import Util.Pretty(pretty, text)
5454
5555data MArgTy = IA Name | EA Name | CA deriving Show
5656
57−elabClass :: ElabInfo -> SyntaxInfo -> Docstring (Either Err PTerm) ->
58− FC -> [(Name, PTerm)] ->
59− Name -> FC -> [(Name, FC, PTerm)] -> [(Name, Docstring (Either Err PTerm))] ->
60− [(Name, FC)] {- ^ determining params -} ->
61− [PDecl] {- ^ class body -} ->
62− Maybe (Name, FC) {- ^ instance ctor name and location -} ->
63− Docstring (Either Err PTerm) {- ^ instance ctor docs -} ->
64− Idris ()
57+elabClass :: ElabInfo
58+ -> SyntaxInfo
59+ -> Docstring (Either Err PTerm)
60+ -> FC
61+ -> [(Name, PTerm)]
62+ -> Name
63+ -> FC
64+ -> [(Name, FC, PTerm)]
65+ -> [(Name, Docstring (Either Err PTerm))]
66+ -> [(Name, FC)] -- ^ determining params
67+ -> [PDecl] -- ^ class body
68+ -> Maybe (Name, FC) -- ^ instance ctor name and location
69+ -> Docstring (Either Err PTerm) -- ^ instance ctor docs
70+ -> Idris ()
6571elabClass info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
6672 = do let cn = fromMaybe (SN (InstanceCtorN tn)) (fst <$> mcn)
6773 let tty = pibind (map (\(n, _, ty) -> (n, ty)) ps) (PType fc)
@@ -79,7 +85,7 @@ elabClass info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
7985 mapM_ checkDefaultSuperclassInstance idecls
8086 let mnames = map getMName mdecls
8187 ist <- getIState
82− let constraintNames = nub $
88+ let constraintNames = nub $
8389 concatMap (namesIn [] ist) (map snd constraints)
8490
8591 mapM_ (checkConstraintName (map (\(x, _, _) -> x) ps)) constraintNames
@@ -161,10 +167,10 @@ elabClass info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
161167
162168 checkConstraintName :: [Name] -> Name -> Idris ()
163169 checkConstraintName bound cname
164− | cname `notElem` bound
165− = tclift $ tfail (At fc (Msg $ "Name " ++ show cname ++
170+ | cname `notElem` bound
171+ = tclift $ tfail (At fc (Msg $ "Name " ++ show cname ++
166172 " is not bound in interface " ++ show tn
167− ++ " " ++ showSep " " (map show bound)))
173+ ++ " " ++ showSep " " (map show bound)))
168174 | otherwise = return ()
169175
170176 impbind :: [(Name, PTerm)] -> PTerm -> PTerm
@@ -185,7 +191,7 @@ elabClass info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
185191 (n, (False, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
186192 (\ l s p -> Imp l s p Nothing True) t'))),
187193 (n, (nfc, syn, o, t) ) )
188− tdecl allmeths (PData doc _ syn _ _ (PLaterdecl n nfc t))
194+ tdecl allmeths (PData doc _ syn _ _ (PLaterdecl n nfc t))
189195 = do let o = []
190196 t' <- implicit' info syn (map (\(n, _, _) -> n) ps ++ allmeths) n t
191197 logElab 2 $ "Data method " ++ show n ++ " : " ++ showTmImpls t'
@@ -193,7 +199,7 @@ elabClass info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
193199 (n, (True, nfc, doc, o, (toExp (map (\(pn, _, _) -> pn) ps)
194200 (\ l s p -> Imp l s p Nothing True) t'))),
195201 (n, (nfc, syn, o, t) ) )
196− tdecl allmeths (PData doc _ syn _ _ _)
202+ tdecl allmeths (PData doc _ syn _ _ _)
197203 = ierror $ At fc (Msg "Data definitions not allowed in a class declaration")
198204 tdecl _ _ = ierror $ At fc (Msg "Not allowed in a class declaration")
199205
@@ -292,19 +298,19 @@ elabClass info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
292298 -- Also ensure the dictionary is used for lookup of any methods that
293299 -- are used in the type
294300 insertConstraint :: PTerm -> [Name] -> PTerm -> PTerm
295− insertConstraint c all sc
296− = let dictN = sMN 0 "__class" in
301+ insertConstraint c all sc
302+ = let dictN = sMN 0 "__class" in
297303 PPi (constraint { pstatic = Static })
298304 dictN NoFC c
299305 (constrainMeths (map basename all)
300306 dictN sc)
301− where
307+ where
302308 -- After we insert the constraint into the lookup, we need to
303309 -- ensure that the same dictionary is used to resolve lookups
304310 -- to the other methods in the class
305311 constrainMeths :: [Name] -> Name -> PTerm -> PTerm
306312 constrainMeths allM dictN tm = transform (addC allM dictN) tm
307−
313+
308314 addC allM dictN m@(PRef fc hls n)
309315 | n `elem` allM = PApp NoFC m [pconst (PRef NoFC hls dictN)]
310316 | otherwise = m
src/Idris/Elab/Clause.hs+8−8
@@ -512,7 +512,7 @@ findUnique ctxt env (Bind n b sc)
512512 else findUnique ctxt ((n, b) : env) sc
513513findUnique _ _ _ = []
514514
515−-- Return the elaborated LHS/RHS, and the original LHS with implicits added
515+-- | Return the elaborated LHS/RHS, and the original LHS with implicits added
516516elabClause :: ElabInfo -> FnOpts -> (Int, PClause) ->
517517 Idris (Either Term (Term, Term), PTerm)
518518elabClause info opts (_, PClause fc fname lhs_in [] PImpossible [])
@@ -554,7 +554,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
554554
555555 let lhs = mkLHSapp $ stripLinear i $ stripUnmatchable i $
556556 propagateParams i params norm_ty (allNamesIn lhs_in) (addImplPat i lhs_in)
557−
557+
558558-- let lhs = mkLHSapp $
559559-- propagateParams i params fn_ty (addImplPat i lhs_in)
560560 logElab 10 (show (params, fn_ty) ++ " " ++ showTmImpls (addImplPat i lhs_in))
@@ -704,7 +704,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
704704 -- allow the deferred things to be definable
705705 -- (this is just to allow users to inspect intermediate
706706 -- things)
707− <- if (null holes || null def') && not inf
707+ <- if (null holes || null def') && not inf
708708 then recheckC_borrowing True (PEGenerated `notElem` opts)
709709 borrowed fc id [] rhs'
710710 else return (rhs', clhsty)
@@ -1033,7 +1033,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in pn_in withblock)
10331033 | otherwise = Placeholder
10341034
10351035 updateWithTerm :: IState -> Maybe Name -> Name -> PTerm -> [Name] -> [Name] -> PTerm -> PTerm
1036− updateWithTerm ist pn wname toplhs ns_in ns_in' tm
1036+ updateWithTerm ist pn wname toplhs ns_in ns_in' tm
10371037 = mapPT updateApp tm
10381038 where
10391039 arity (PApp _ _ as) = length as
@@ -1097,18 +1097,18 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in pn_in withblock)
10971097
10981098 abstract wn wv wty (n, argty) = (n, substTerm wv (P Bound wn wty) argty)
10991099
1100−-- Apply a transformation to all RHSes and nested RHSs
1100+-- | Apply a transformation to all RHSes and nested RHSs
11011101mapRHS :: (PTerm -> PTerm) -> PClause -> PClause
1102−mapRHS f (PClause fc n lhs args rhs ws)
1102+mapRHS f (PClause fc n lhs args rhs ws)
11031103 = PClause fc n lhs args (f rhs) (map (mapRHSdecl f) ws)
11041104mapRHS f (PWith fc n lhs args warg prf ws)
11051105 = PWith fc n lhs args (f warg) prf (map (mapRHSdecl f) ws)
1106−mapRHS f (PClauseR fc args rhs ws)
1106+mapRHS f (PClauseR fc args rhs ws)
11071107 = PClauseR fc args (f rhs) (map (mapRHSdecl f) ws)
11081108mapRHS f (PWithR fc args warg prf ws)
11091109 = PWithR fc args (f warg) prf (map (mapRHSdecl f) ws)
11101110
11111111mapRHSdecl :: (PTerm -> PTerm) -> PDecl -> PDecl
1112−mapRHSdecl f (PClauses fc opt n cs)
1112+mapRHSdecl f (PClauses fc opt n cs)
11131113 = PClauses fc opt n (map (mapRHS f) cs)
11141114mapRHSdecl f t = t
src/Idris/Elab/Instance.hs+44−42
@@ -50,21 +50,24 @@ import Data.List.Split (splitOn)
5050
5151import Util.Pretty(pretty, text)
5252
53−elabInstance :: ElabInfo -> SyntaxInfo ->
54− Docstring (Either Err PTerm) ->
55− [(Name, Docstring (Either Err PTerm))] ->
56− ElabWhat -> -- phase
57− FC -> [(Name, PTerm)] -> -- constraints
58− [Name] -> -- parent dictionary names (optionally)
59− Accessibility ->
60− FnOpts ->
61− Name -> -- the class
62− FC -> -- precise location of class name
63− [PTerm] -> -- class parameters (i.e. instance)
64− [(Name, PTerm)] -> -- Extra arguments in scope (e.g. instance in where block)
65− PTerm -> -- full instance type
66− Maybe Name -> -- explicit name
67− [PDecl] -> Idris ()
53+elabInstance :: ElabInfo
54+ -> SyntaxInfo
55+ -> Docstring (Either Err PTerm)
56+ -> [(Name, Docstring (Either Err PTerm))]
57+ -> ElabWhat -- ^ phase
58+ -> FC
59+ -> [(Name, PTerm)] -- ^ constraints
60+ -> [Name] -- ^ parent dictionary names (optionally)
61+ -> Accessibility
62+ -> FnOpts
63+ -> Name -- ^ the class
64+ -> FC -- ^ precise location of class name
65+ -> [PTerm] -- ^ class parameters (i.e. instance)
66+ -> [(Name, PTerm)] -- ^ Extra arguments in scope (e.g. instance in where block)
67+ -> PTerm -- ^ full instance type
68+ -> Maybe Name -- ^ explicit name
69+ -> [PDecl]
70+ -> Idris ()
6871elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t expn ds = do
6972 ist <- getIState
7073 (n, ci) <- case lookupCtxtName n (idris_classes ist) of
@@ -81,7 +84,7 @@ elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t
8184
8285 let emptyclass = null (class_methods ci)
8386 when (what /= EDefns) $ do
84− nty <- elabType' True info syn doc argDocs fc totopts iname NoFC
87+ nty <- elabType' True info syn doc argDocs fc totopts iname NoFC
8588 (piBindp expl_param pextra t)
8689 -- if the instance type matches any of the instances we have already,
8790 -- and it's not a named instance, then it's overlapping, so report an error
@@ -111,7 +114,7 @@ elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t
111114 let superclassInstances = map (substInstance ips pnames) (class_default_superclasses ci)
112115 undefinedSuperclassInstances <- filterM (fmap not . isOverlapping ist) superclassInstances
113116 mapM_ (rec_elabDecl info EAll info) undefinedSuperclassInstances
114−
117+
115118 ist <- getIState
116119 -- Bring variables in instance head into scope when building the
117120 -- dictionary
@@ -121,11 +124,11 @@ elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t
121124 Just ty -> (map (\n -> (n, getTypeIn ist n ty)) headVars, ty)
122125 _ -> (zip headVars (repeat Placeholder), Erased)
123126 logElab 3 $ "Head var types " ++ show headVarTypes ++ " from " ++ show ty
124−
127+
125128 let all_meths = map (nsroot . fst) (class_methods ci)
126129 let mtys = map (\ (n, (inj, op, t)) ->
127130 let t_in = substMatchesShadow ips pnames t
128− mnamemap =
131+ mnamemap =
129132 map (\n -> (n, PApp fc (PRef fc [] (decorate ns iname n))
130133 (map (toImp fc) headVars)))
131134 all_meths
@@ -182,13 +185,13 @@ elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t
182185 Nothing -> []
183186 let prop_params = getParamsInType ist [] ifn_is ifn_ty
184187
185− logElab 3 $ "Propagating parameters to methods: "
188+ logElab 3 $ "Propagating parameters to methods: "
186189 ++ show (iname, prop_params)
187190
188191 let wbVals' = map (addParams prop_params) wbVals
189192
190193 mapM_ (rec_elabDecl info EAll info) wbVals'
191−
194+
192195 mapM_ (checkInjectiveDef fc (class_methods ci)) (zip ds' wbVals')
193196
194197 pop_estack
@@ -212,8 +215,8 @@ elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t
212215 Just nm -> nm
213216
214217 substInstance ips pnames (PInstance doc argDocs syn _ cs parents acc opts n nfc ps pextra t expn ds)
215− = PInstance doc argDocs syn fc cs parents acc opts n nfc
216− (map (substMatchesShadow ips pnames) ps)
218+ = PInstance doc argDocs syn fc cs parents acc opts n nfc
219+ (map (substMatchesShadow ips pnames) ps)
217220 pextra
218221 (substMatchesShadow ips pnames t) expn ds
219222
@@ -275,10 +278,10 @@ elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t
275278 keepDets dets t = t
276279
277280 methName (n, _, _, _) = n
278− toExp n = pexp (PRef fc [] n)
281+ toExp n = pexp (PRef fc [] n)
279282
280− mkMethApp ps (n, _, _, ty)
281− = lamBind 0 ty (papp fc (PRef fc [] n)
283+ mkMethApp ps (n, _, _, ty)
284+ = lamBind 0 ty (papp fc (PRef fc [] n)
282285 (ps ++ map (toExp . fst) pextra ++ methArgs 0 ty))
283286 where
284287 needed is p = pname p `elem` map pname is
@@ -311,7 +314,7 @@ elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t
311314
312315 decorate ns iname (NS (UN nm) s)
313316 = NS (SN (WhereN 0 iname (SN (MethodN (UN nm))))) ns
314− decorate ns iname nm
317+ decorate ns iname nm
315318 = NS (SN (WhereN 0 iname (SN (MethodN nm)))) ns
316319
317320 mkTyDecl (n, op, t, _)
@@ -375,7 +378,7 @@ elabInstance info syn doc argDocs what fc cs parents acc opts n nfc ps pextra t
375378 clauseFor m iname ns (PClauses _ _ m' _)
376379 = decorate ns iname m == decorate ns iname m'
377380 clauseFor m iname ns _ = False
378−
381+
379382getHeadVars :: PTerm -> [Name]
380383getHeadVars (PRef _ _ n) | implicitable n = [n]
381384getHeadVars (PApp _ _ args) = concatMap getHeadVars (map getTm args)
@@ -383,14 +386,14 @@ getHeadVars (PPair _ _ _ l r) = getHeadVars l ++ getHeadVars r
383386getHeadVars (PDPair _ _ _ l t r) = getHeadVars l ++ getHeadVars t ++ getHeadVars t
384387getHeadVars _ = []
385388
386−-- Implicitly bind variables from the instance head in method types
389+-- | Implicitly bind variables from the instance head in method types
387390impBind :: [(Name, PTerm)] -> PDecl -> PDecl
388391impBind vs (PTy d ds syn fc opts n fc' t)
389− = PTy d ds syn fc opts n fc'
392+ = PTy d ds syn fc opts n fc'
390393 (doImpBind (filter (\(n, ty) -> n `notElem` boundIn t) vs) t)
391394 where
392395 doImpBind [] ty = ty
393− doImpBind ((n, argty) : ns) ty
396+ doImpBind ((n, argty) : ns) ty
394397 = PPi impl n NoFC argty (doImpBind ns ty)
395398
396399 boundIn (PPi _ n _ _ sc) = n : boundIn sc
@@ -404,19 +407,19 @@ getTypeIn ist n tm = Placeholder
404407
405408toImp fc n = pimp n (PRef fc [] n) True
406409
407−-- Propagate class parameters to method bodies, if they're not already
408−-- there, and they are needed (i.e. appear in method's type)
410+-- | Propagate class parameters to method bodies, if they're not
411+-- already there, and they are needed (i.e. appear in method's type)
409412addParams :: [Name] -> PDecl -> PDecl
410413addParams ps (PClauses fc opts n cs) = PClauses fc opts n (map addCParams cs)
411414 where
412415 addCParams (PClause fc n lhs ws rhs wb)
413416 = PClause fc n (addTmParams (dropPs (allNamesIn lhs) ps) lhs) ws rhs wb
414417 addCParams (PWith fc n lhs ws sc pn ds)
415− = PWith fc n (addTmParams (dropPs (allNamesIn lhs) ps) lhs) ws sc pn
418+ = PWith fc n (addTmParams (dropPs (allNamesIn lhs) ps) lhs) ws sc pn
416419 (map (addParams ps) ds)
417420 addCParams c = c
418421
419− addTmParams ps (PRef fc hls n)
422+ addTmParams ps (PRef fc hls n)
420423 = PApp fc (PRef fc hls n) (map (toImp fc) ps)
421424 addTmParams ps (PApp fc ap@(PRef fc' hls n) args)
422425 = PApp fc ap (mergePs (map (toImp fc) ps) args)
@@ -439,11 +442,10 @@ addParams ps (PClauses fc opts n cs) = PClauses fc opts n (map addCParams cs)
439442
440443addParams ps d = d
441444
442−-- Check a given method definition is injective, if the class info
443−-- says it needs to be.
444−-- Takes originally written decl and the one with name decoration, so
445−-- we know which name to look up.
446−checkInjectiveDef :: FC -> [(Name, (Bool, FnOpts, PTerm))] ->
445+-- | Check a given method definition is injective, if the class info
446+-- says it needs to be. Takes originally written decl and the one
447+-- with name decoration, so we know which name to look up.
448+checkInjectiveDef :: FC -> [(Name, (Bool, FnOpts, PTerm))] ->
447449 (PDecl, PDecl) -> Idris ()
448450checkInjectiveDef fc ns (PClauses _ _ n cs, PClauses _ _ elabn _)
449451 | Just (True, _, _) <- clookup n ns
@@ -452,13 +454,13 @@ checkInjectiveDef fc ns (PClauses _ _ n cs, PClauses _ _ elabn _)
452454 Just (CaseOp _ _ _ _ _ cdefs) ->
453455 checkInjectiveCase ist (snd (cases_compiletime cdefs))
454456 where
455− checkInjectiveCase ist (STerm tm)
457+ checkInjectiveCase ist (STerm tm)
456458 = checkInjectiveApp ist (fst (unApply tm))
457459 checkInjectiveCase _ _ = notifail
458460
459461 checkInjectiveApp ist (P (TCon _ _) n _) = return ()
460462 checkInjectiveApp ist (P (DCon _ _ _) n _) = return ()
461− checkInjectiveApp ist (P Ref n _)
463+ checkInjectiveApp ist (P Ref n _)
462464 | Just True <- lookupInjectiveExact n (tt_ctxt ist) = return ()
463465 checkInjectiveApp ist (P Ref n _) = notifail
464466 checkInjectiveApp _ _ = notifail
src/Idris/Elab/Record.hs+38−34
@@ -35,16 +35,18 @@ import Control.Monad
3535-- | Elaborate a record declaration
3636elabRecord :: ElabInfo
3737 -> ElabWhat
38− -> (Docstring (Either Err PTerm)) -- ^ The documentation for the whole declaration
39− -> SyntaxInfo -> FC -> DataOpts
40− -> Name -- ^ The name of the type being defined
41− -> FC -- ^ The precise source location of the tycon name
42− -> [(Name, FC, Plicity, PTerm)] -- ^ Parameters
43− -> [(Name, Docstring (Either Err PTerm))] -- ^ Parameter Docs
38+ -> (Docstring (Either Err PTerm)) -- ^ The documentation for the whole declaration
39+ -> SyntaxInfo
40+ -> FC
41+ -> DataOpts
42+ -> Name -- ^ The name of the type being defined
43+ -> FC -- ^ The precise source location of the tycon name
44+ -> [(Name, FC, Plicity, PTerm)] -- ^ Parameters
45+ -> [(Name, Docstring (Either Err PTerm))] -- ^ Parameter Docs
4446 -> [(Maybe (Name, FC), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -- ^ Fields
45− -> Maybe (Name, FC) -- ^ Constructor Name
46− -> (Docstring (Either Err PTerm)) -- ^ Constructor Doc
47− -> SyntaxInfo -- ^ Constructor SyntaxInfo
47+ -> Maybe (Name, FC) -- ^ Constructor Name
48+ -> (Docstring (Either Err PTerm)) -- ^ Constructor Doc
49+ -> SyntaxInfo -- ^ Constructor SyntaxInfo
4850 -> Idris ()
4951elabRecord info what doc rsyn fc opts tyn nfc params paramDocs fields cname cdoc csyn
5052 = do logElab 1 $ "Building data declaration for " ++ show tyn
@@ -154,12 +156,14 @@ elabRecord info what doc rsyn fc opts tyn nfc params paramDocs fields cname cdoc
154156 in (n, nfc, p, t, doc) : (fwnad rest)
155157 fwnad [] = []
156158
157−elabRecordFunctions :: ElabInfo -> SyntaxInfo -> FC
158− -> Name -- ^ Record type name
159+elabRecordFunctions :: ElabInfo
160+ -> SyntaxInfo
161+ -> FC
162+ -> Name -- ^ Record type name
159163 -> [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Parameters
160164 -> [(Name, FC, Plicity, PTerm, Docstring (Either Err PTerm))] -- ^ Fields
161− -> Name -- ^ Constructor Name
162− -> PTerm -- ^ Target type
165+ -> Name -- ^ Constructor Name
166+ -> PTerm -- ^ Target type
163167 -> Idris ()
164168elabRecordFunctions info rsyn fc tyn params fields dconName target
165169 = do logElab 1 $ "Elaborating helper functions for record " ++ show tyn
@@ -301,17 +305,17 @@ elabRecordFunctions info rsyn fc tyn params fields dconName target
301305
302306-- | Creates and elaborates a projection function.
303307elabProjection :: ElabInfo
304− -> Name -- ^ Name of the argument in the constructor
305− -> Name -- ^ Projection Name
306− -> Plicity -- ^ Projection Plicity
307− -> PTerm -- ^ Projection Type
308+ -> Name -- ^ Name of the argument in the constructor
309+ -> Name -- ^ Projection Name
310+ -> Plicity -- ^ Projection Plicity
311+ -> PTerm -- ^ Projection Type
308312 -> (Docstring (Either Err PTerm)) -- ^ Projection Documentation
309− -> SyntaxInfo -- ^ Projection SyntaxInfo
310− -> FC -> PTerm -- ^ Projection target type
311− -> Name -- ^ Data constructor tame
312− -> [PArg] -- ^ Placeholder Arguments to constructor
313− -> [Name] -- ^ All Field Names
314− -> Int -- ^ Argument Index
313+ -> SyntaxInfo -- ^ Projection SyntaxInfo
314+ -> FC -> PTerm -- ^ Projection target type
315+ -> Name -- ^ Data constructor tame
316+ -> [PArg] -- ^ Placeholder Arguments to constructor
317+ -> [Name] -- ^ All Field Names
318+ -> Int -- ^ Argument Index
315319 -> Idris ()
316320elabProjection info cname pname plicity projTy pdoc psyn fc targetTy cn phArgs fnames index
317321 = do logElab 1 $ "Generating Projection for " ++ show pname
@@ -358,18 +362,18 @@ elabProjection info cname pname plicity projTy pdoc psyn fc targetTy cn phArgs f
358362-- | Creates and elaborates an update function.
359363-- If 'optional' is true, we will not fail if we can't elaborate the update function.
360364elabUpdate :: ElabInfo
361− -> Name -- ^ Name of the argument in the constructor
362− -> Name -- ^ Field Name
363− -> Plicity -- ^ Field Plicity
364− -> PTerm -- ^ Field Type
365+ -> Name -- ^ Name of the argument in the constructor
366+ -> Name -- ^ Field Name
367+ -> Plicity -- ^ Field Plicity
368+ -> PTerm -- ^ Field Type
365369 -> (Docstring (Either Err PTerm)) -- ^ Field Documentation
366− -> SyntaxInfo -- ^ Field SyntaxInfo
367− -> FC -> PTerm -- ^ Projection Source Type
368− -> Name -- ^ Data Constructor Name
369− -> [PArg] -- ^ Arguments to constructor
370− -> [Name] -- ^ All fields
371− -> Int -- ^ Argument Index
372− -> Bool -- ^ Optional
370+ -> SyntaxInfo -- ^ Field SyntaxInfo
371+ -> FC -> PTerm -- ^ Projection Source Type
372+ -> Name -- ^ Data Constructor Name
373+ -> [PArg] -- ^ Arguments to constructor
374+ -> [Name] -- ^ All fields
375+ -> Int -- ^ Argument Index
376+ -> Bool -- ^ Optional
373377 -> Idris ()
374378elabUpdate info cname pname plicity pty pdoc psyn fc sty cn args fnames i optional
375379 = do logElab 1 $ "Generating Update for " ++ show pname
src/Idris/Elab/Rewrite.hs+27−27
@@ -17,7 +17,7 @@ import Data.List
1717
1818import Debug.Trace
1919
20−elabRewrite :: (PTerm -> ElabD ()) -> IState ->
20+elabRewrite :: (PTerm -> ElabD ()) -> IState ->
2121 FC -> Maybe Name -> PTerm -> PTerm -> Maybe PTerm -> ElabD ()
2222-- Old version, no rewrite rule given
2323{-
@@ -47,7 +47,7 @@ elabRewrite elab ist fc substfn_in rule sc_in newg
4747 Nothing -> return sc_in
4848 Just t -> do
4949 letn <- getNameFrom (sMN 0 "rewrite_result")
50− return $ PLet fc letn fc t sc_in
50+ return $ PLet fc letn fc t sc_in
5151 (PRef fc [] letn)
5252 tyn <- getNameFrom (sMN 0 "rty")
5353 claim tyn RType
@@ -75,7 +75,7 @@ elabRewrite elab ist fc substfn_in rule sc_in newg
7575 [pexp pred, pexp rule, pexp sc])
7676-- trace ("LHS: " ++ show l ++ "\n" ++
7777-- "RHS: " ++ show r ++ "\n" ++
78−-- "REWRITE: " ++ show rewrite ++ "\n" ++
78+-- "REWRITE: " ++ show rewrite ++ "\n" ++
7979-- "GOAL: " ++ show (delab ist g)) $
8080 elab rewrite
8181 solve
@@ -84,7 +84,7 @@ elabRewrite elab ist fc substfn_in rule sc_in newg
8484 mkP :: TT Name -> -- Left term, top level
8585 TT Name -> TT Name -> TT Name -> TT Name
8686 mkP lt l r ty | l == ty = lt
87− mkP lt l r (App s f a)
87+ mkP lt l r (App s f a)
8888 = let f' = if (r /= f) then mkP lt l r f else f
8989 a' = if (r /= a) then mkP lt l r a else a in
9090 App s f' a'
@@ -101,7 +101,7 @@ elabRewrite elab ist fc substfn_in rule sc_in newg
101101 mkP lt l r x = x
102102
103103 -- If we're rewriting a dependent type, the rewrite type the rewrite
104− -- may break the indices.
104+ -- may break the indices.
105105 -- So, for any function argument which can be determined by looking
106106 -- at the indices (i.e. any constructor guarded elsewhere in the type)
107107 -- replace it with a _. e.g. (++) a n m xs ys becomes (++) _ _ _ xs ys
@@ -116,7 +116,7 @@ elabRewrite elab ist fc substfn_in rule sc_in newg
116116 where removeImp tm@(PImp{}) = tm { getTm = Placeholder }
117117 removeImp t = t
118118 phApps tm = tm
119−
119+
120120findSubstFn :: Maybe Name -> IState -> Type -> Type -> ElabD Name
121121findSubstFn Nothing ist lt rt
122122 | lt == rt = return (sUN "rewrite__impl")
@@ -129,8 +129,8 @@ findSubstFn Nothing ist lt rt
129129 Just _ -> return (rewrite_name lcon)
130130 Nothing -> rewriteFail lt rt
131131 | otherwise = rewriteFail lt rt
132− where rewriteFail lt rt = lift . tfail .
133− Msg $ "Can't rewrite heterogeneous equality on types " ++
132+ where rewriteFail lt rt = lift . tfail .
133+ Msg $ "Can't rewrite heterogeneous equality on types " ++
134134 show (delab ist lt) ++ " and " ++ show (delab ist rt)
135135
136136findSubstFn (Just substfn_in) ist lt rt
@@ -142,8 +142,8 @@ findSubstFn (Just substfn_in) ist lt rt
142142rewrite_name :: Name -> Name
143143rewrite_name n = sMN 0 (show n ++ "_rewrite_lemma")
144144
145−data ParamInfo = Index
146− | Param
145+data ParamInfo = Index
146+ | Param
147147 | ImplicitIndex
148148 | ImplicitParam
149149 deriving Show
@@ -163,9 +163,11 @@ isParam Param = True
163163isParam ImplicitIndex = False
164164isParam ImplicitParam = True
165165
166−-- Make a rewriting lemma for the given type constructor.
167−-- If it fails, fail silently (it may well fail for some very complex types.
168−-- We can fix this later, for now this gives us a lot more working rewrites...)
166+-- | Make a rewriting lemma for the given type constructor.
167+--
168+-- If it fails, fail silently (it may well fail for some very complex
169+-- types. We can fix this later, for now this gives us a lot more
170+-- working rewrites...)
169171elabRewriteLemma :: ElabInfo -> Name -> Type -> Idris ()
170172elabRewriteLemma info n cty_in =
171173 do ist <- getIState
@@ -176,7 +178,7 @@ elabRewriteLemma info n cty_in =
176178 Just ti -> do
177179 let imps = case lookupCtxtExact n (idris_implicits ist) of
178180 Nothing -> repeat (pexp Placeholder)
179− Just is -> is
181+ Just is -> is
180182 let pinfo = getParamInfo cty imps 0 (param_pos ti)
181183 if all isParam pinfo
182184 then return () -- no need for a lemma, = will be homogeneous
@@ -189,7 +191,7 @@ mkLemma info lemma tcon ps ty =
189191 let leftty = mkTy tcon ps (namesFrom "p" 0) (namesFrom "left" 0)
190192 rightty = mkTy tcon ps (namesFrom "p" 0) (namesFrom "right" 0)
191193 predty = bindIdxs ist ps ty (namesFrom "pred" 0) $
192− PPi expl (sMN 0 "rep") fc
194+ PPi expl (sMN 0 "rep") fc
193195 (mkTy tcon ps (namesFrom "p" 0) (namesFrom "pred" 0))
194196 (PType fc)
195197 let xarg = sMN 0 "x"
@@ -215,8 +217,8 @@ mkLemma info lemma tcon ps ty =
215217 let lemRHS = PRef fc [] prop
216218
217219 -- Elaborate the type of the lemma
218− rec_elabDecl info EAll info
219− (PTy emptyDocstring [] defaultSyntax fc [] lemma fc lemTy)
220+ rec_elabDecl info EAll info
221+ (PTy emptyDocstring [] defaultSyntax fc [] lemma fc lemTy)
220222 -- Elaborate the definition
221223 rec_elabDecl info EAll info
222224 (PClauses fc [] lemma [PClause fc lemma lemLHS [] lemRHS []])
@@ -224,9 +226,9 @@ mkLemma info lemma tcon ps ty =
224226 where
225227 fc = emptyFC
226228
227− namesFrom x i = sMN i x : namesFrom x (i + 1)
228−
229− mkTy fn pinfo ps is
229+ namesFrom x i = sMN i x : namesFrom x (i + 1)
230+
231+ mkTy fn pinfo ps is
230232 = PApp fc (PRef fc [] fn) (mkArgs pinfo ps is)
231233
232234 mkArgs [] ps is = []
@@ -241,15 +243,13 @@ mkLemma info lemma tcon ps ty =
241243 mkArgs _ _ _ = []
242244
243245 bindIdxs ist [] ty is tm = tm
244− bindIdxs ist (Param : pinfo) (Bind n (Pi _ ty _) sc) is tm
246+ bindIdxs ist (Param : pinfo) (Bind n (Pi _ ty _) sc) is tm
245247 = bindIdxs ist pinfo (instantiate (P Bound n ty) sc) is tm
246− bindIdxs ist (Index : pinfo) (Bind n (Pi _ ty _) sc) (i : is) tm
247− = PPi forall_imp i fc (delab ist ty)
248+ bindIdxs ist (Index : pinfo) (Bind n (Pi _ ty _) sc) (i : is) tm
249+ = PPi forall_imp i fc (delab ist ty)
248250 (bindIdxs ist pinfo (instantiate (P Bound n ty) sc) is tm)
249− bindIdxs ist (ImplicitParam : pinfo) (Bind n (Pi _ ty _) sc) is tm
251+ bindIdxs ist (ImplicitParam : pinfo) (Bind n (Pi _ ty _) sc) is tm
250252 = bindIdxs ist pinfo (instantiate (P Bound n ty) sc) is tm
251− bindIdxs ist (ImplicitIndex : pinfo) (Bind n (Pi _ ty _) sc) (i : is) tm
253+ bindIdxs ist (ImplicitIndex : pinfo) (Bind n (Pi _ ty _) sc) (i : is) tm
252254 = bindIdxs ist pinfo (instantiate (P Bound n ty) sc) is tm
253255 bindIdxs _ _ _ _ tm = tm
254−
255−
src/Idris/Elab/Term.hs+48−36
@@ -42,33 +42,38 @@ data ElabMode = ETyDecl | ETransLHS | ELHS | ERHS
4242 deriving Eq
4343
4444
45−data ElabResult =
46− ElabResult { resultTerm :: Term -- ^ The term resulting from elaboration
47− , resultMetavars :: [(Name, (Int, Maybe Name, Type, [Name]))]
48− -- ^ Information about new metavariables
49− , resultCaseDecls :: [PDecl]
50− -- ^ Deferred declarations as the meaning of case blocks
51− , resultContext :: Context
52− -- ^ The potentially extended context from new definitions
53− , resultTyDecls :: [RDeclInstructions]
54− -- ^ Meta-info about the new type declarations
55− , resultHighlighting :: [(FC, OutputAnnotation)]
56− -- ^ Saved highlights from elaboration
57− , resultName :: Int
58− -- ^ The new global name counter
59− }
60−
61−
62−-- Using the elaborator, convert a term in raw syntax to a fully
45+data ElabResult = ElabResult {
46+ -- | The term resulting from elaboration
47+ resultTerm :: Term
48+ -- | Information about new metavariables
49+ , resultMetavars :: [(Name, (Int, Maybe Name, Type, [Name]))]
50+ -- | Deferred declarations as the meaning of case blocks
51+ , resultCaseDecls :: [PDecl]
52+ -- | The potentially extended context from new definitions
53+ , resultContext :: Context
54+ -- | Meta-info about the new type declarations
55+ , resultTyDecls :: [RDeclInstructions]
56+ -- | Saved highlights from elaboration
57+ , resultHighlighting :: [(FC, OutputAnnotation)]
58+ -- | The new global name counter
59+ , resultName :: Int
60+ }
61+
62+
63+-- | Using the elaborator, convert a term in raw syntax to a fully
6364-- elaborated, typechecked term.
6465--
6566-- If building a pattern match, we convert undeclared variables from
6667-- holes to pattern bindings.
67−
68+--
6869-- Also find deferred names in the term and their types
69−
70−build :: IState -> ElabInfo -> ElabMode -> FnOpts -> Name -> PTerm ->
71− ElabD ElabResult
70+build :: IState
71+ -> ElabInfo
72+ -> ElabMode
73+ -> FnOpts
74+ -> Name
75+ -> PTerm
76+ -> ElabD ElabResult
7277build ist info emode opts fn tm
7378 = do elab ist info emode opts fn tm
7479 let tmIn = tm
@@ -139,7 +144,8 @@ build ist info emode opts fn tm
139144 (h: hs) -> do patvar h; mkPat
140145 [] -> return ()
141146
142−-- Build a term autogenerated as a typeclass method definition
147+-- | Build a term autogenerated as a typeclass method definition.
148+--
143149-- (Separate, so we don't go overboard resolving things that we don't
144150-- know about yet on the LHS of a pattern def)
145151
@@ -177,9 +183,10 @@ buildTC ist info emode opts fn ns tm
177183 else return (ElabResult tm ds (map snd is) ctxt impls highlights g_nextname)
178184 where pattern = emode == ELHS
179185
180−-- return whether arguments of the given constructor name can be
181−-- matched on. If they're polymorphic, no, unless the type has beed made
182−-- concrete by the time we get around to elaborating the argument.
186+-- | return whether arguments of the given constructor name can be
187+-- matched on. If they're polymorphic, no, unless the type has beed
188+-- made concrete by the time we get around to elaborating the
189+-- argument.
183190getUnmatchable :: Context -> Name -> [Bool]
184191getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
185192 = case lookupTyExact n ctxt of
@@ -220,8 +227,13 @@ goal_polymorphic =
220227-- | Returns the set of declarations we need to add to complete the
221228-- definition (most likely case blocks to elaborate) as well as
222229-- declarations resulting from user tactic scripts (%runElab)
223−elab :: IState -> ElabInfo -> ElabMode -> FnOpts -> Name -> PTerm ->
224− ElabD ()
230+elab :: IState
231+ -> ElabInfo
232+ -> ElabMode
233+ -> FnOpts
234+ -> Name
235+ -> PTerm
236+ -> ElabD ()
225237elab ist info emode opts fn tm
226238 = do let loglvl = opt_logLevel (idris_options ist)
227239 when (loglvl > 5) $ unifyLog True
@@ -1438,7 +1450,7 @@ elab ist info emode opts fn tm
14381450 return (mkPApp fc a ftm args)
14391451 _ -> return tm
14401452 expandToArity t = return t
1441−
1453+
14421454 fullApp (PApp _ (PApp fc f args) xs) = fullApp (PApp fc f (args ++ xs))
14431455 fullApp x = x
14441456
@@ -1550,11 +1562,11 @@ elab ist info emode opts fn tm
15501562 addAutoBind _ _ = return ()
15511563
15521564 testImplicitWarning :: FC -> Name -> Type -> ElabD ()
1553− testImplicitWarning fc n goal
1565+ testImplicitWarning fc n goal
15541566 | implicitable n && emode == ETyDecl
15551567 = do env <- get_env
15561568 est <- getAux
1557− when (n `elem` auto_binds est) $
1569+ when (n `elem` auto_binds est) $
15581570 tryUnify env (lookupTyName n (tt_ctxt ist))
15591571 | otherwise = return ()
15601572 where
@@ -1564,7 +1576,7 @@ elab ist info emode opts fn tm
15641576 hs <- get_holes
15651577 case unify (tt_ctxt ist) env (ty, Nothing) (goal, Nothing)
15661578 inj hs [] [] of
1567− OK _ ->
1579+ OK _ ->
15681580 updateAux (\est -> est { implicit_warnings =
15691581 (fc, nm) : implicit_warnings est })
15701582 _ -> tryUnify env ts
@@ -1645,7 +1657,7 @@ pruneByType env (P _ n _) goalty ist as
16451657 = -- trace ("Trying " ++ show f' ++ " for " ++ show n) $
16461658 case lookupTyExact f' ctxt of
16471659 Just ty -> case unApply (getRetTy ty) of
1648− (P _ ctyn _, _) | isTConName ctyn ctxt && not (ctyn == f)
1660+ (P _ ctyn _, _) | isTConName ctyn ctxt && not (ctyn == f)
16491661 -> False
16501662 _ -> let ty' = normalise ctxt [] ty in
16511663-- trace ("Trying " ++ show (getRetTy ty') ++ " for " ++ show goalty) $
@@ -1661,12 +1673,12 @@ pruneByType env (P _ n _) goalty ist as
16611673 _ -> False
16621674
16631675 -- If the goal is a constructor, it must match the suggested function type
1664− matching (P _ ctyn _) (P _ n' _)
1676+ matching (P _ ctyn _) (P _ n' _)
16651677 | isTConName n' ctxt = ctyn == n'
16661678 | otherwise = True
16671679 -- Variables match anything
1668− matching (V _) _ = True
1669− matching _ (V _) = True
1680+ matching (V _) _ = True
1681+ matching _ (V _) = True
16701682 matching _ (P _ n _) = not (isTConName n ctxt)
16711683 matching (P _ n _) _ = not (isTConName n ctxt)
16721684 -- Binders are a plausible match, so keep them
src/Idris/Elab/Type.hs+31−14
@@ -52,8 +52,13 @@ import Data.List.Split (splitOn)
5252
5353import Util.Pretty(pretty, text)
5454
55−buildType :: ElabInfo -> SyntaxInfo -> FC -> FnOpts -> Name -> PTerm ->
56− Idris (Type, Type, PTerm, [(Int, Name)])
55+buildType :: ElabInfo
56+ -> SyntaxInfo
57+ -> FC
58+ -> FnOpts
59+ -> Name
60+ -> PTerm
61+ -> Idris (Type, Type, PTerm, [(Int, Name)])
5762buildType info syn fc opts n ty' = do
5863 ctxt <- getContext
5964 i <- getIState
@@ -69,13 +74,13 @@ buildType info syn fc opts n ty' = do
6974
7075 ((ElabResult tyT' defer is ctxt' newDecls highlights newGName, est), log) <-
7176 tclift $ elaborate ctxt (idris_datatypes i) (idris_name i) n (TType (UVal 0)) initEState
72− (errAt "type of " n Nothing
77+ (errAt "type of " n Nothing
7378 (erunAux fc (build i info ETyDecl [] n ty)))
7479
7580 displayWarnings est
7681 setContext ctxt'
7782 processTacticDecls info newDecls
78− sendHighlighting highlights
83+ sendHighlighting highlights
7984 updateIState $ \i -> i { idris_name = newGName }
8085
8186 let tyT = patToImp tyT'
@@ -108,7 +113,7 @@ buildType info syn fc opts n ty' = do
108113
109114 -- Add the names referenced to the call graph, and check we're not
110115 -- referring to anything less visible
111− -- In particular, a public/export type can not refer to anything
116+ -- In particular, a public/export type can not refer to anything
112117 -- private, but can refer to any public/export
113118 let refs = freeNames cty
114119 nvis <- getFromHideList n
@@ -136,17 +141,29 @@ buildType info syn fc opts n ty' = do
136141 param_pos i ns t = []
137142
138143-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
139−elabType :: ElabInfo -> SyntaxInfo
140− -> Docstring (Either Err PTerm) -> [(Name, Docstring (Either Err PTerm))]
141− -> FC -> FnOpts
142− -> Name -> FC -- ^ The precise location of the name
143− -> PTerm -> Idris Type
144+elabType :: ElabInfo
145+ -> SyntaxInfo
146+ -> Docstring (Either Err PTerm)
147+ -> [(Name, Docstring (Either Err PTerm))]
148+ -> FC
149+ -> FnOpts
150+ -> Name
151+ -> FC -- ^ The precise location of the name
152+ -> PTerm
153+ -> Idris Type
144154elabType = elabType' False
145155
146−elabType' :: Bool -> -- normalise it
147− ElabInfo -> SyntaxInfo ->
148− Docstring (Either Err PTerm) -> [(Name, Docstring (Either Err PTerm))] ->
149− FC -> FnOpts -> Name -> FC -> PTerm -> Idris Type
156+elabType' :: Bool -- normalise it
157+ -> ElabInfo
158+ -> SyntaxInfo
159+ -> Docstring (Either Err PTerm)
160+ -> [(Name, Docstring (Either Err PTerm))]
161+ -> FC
162+ -> FnOpts
163+ -> Name
164+ -> FC
165+ -> PTerm
166+ -> Idris Type
150167elabType' norm info syn doc argDocs fc opts n nfc ty' = {- let ty' = piBind (params info) ty_in
151168 n = liftname info n_in in -}
152169 do checkUndefined fc n
src/Idris/Elab/Utils.hs+8−8
@@ -353,12 +353,14 @@ checkVisibility fc n minAcc acc ref
353353 else return ()
354354
355355
356−-- | Find the type constructor arguments that are parameters, given a list of constructor types.
357−-- Parameters are names which are unchanged across the structure,
358−-- which appear exactly once in the return type of a constructor
359−-- First, find all applications of the constructor, then check over
360−-- them for repeated arguments
361−findParams :: Name -- ^ the name of the family that we are finding parameters for
356+-- | Find the type constructor arguments that are parameters, given a
357+-- list of constructor types.
358+--
359+-- Parameters are names which are unchanged across the structure,
360+-- which appear exactly once in the return type of a constructor
361+-- First, find all applications of the constructor, then check over
362+-- them for repeated arguments
363+findParams :: Name -- ^ the name of the family that we are finding parameters for
362364 -> [Type] -- ^ the declared constructor types
363365 -> [Int]
364366findParams tyn ts =
@@ -448,5 +450,3 @@ propagateParams i ps t bound (PRef fc hls n)
448450 isImplicit (PImp _ _ _ x _ : is) n | x == n = True
449451 isImplicit (_ : is) n = isImplicit is n
450452propagateParams i ps t bound x = x
451−
452−
src/Idris/ElabDecls.hs+3−3
@@ -62,7 +62,7 @@ import Data.List.Split (splitOn)
6262import Util.Pretty(pretty, text)
6363
6464
65−-- Top level elaborator info, supporting recursive elaboration
65+-- | Top level elaborator info, supporting recursive elaboration
6666recinfo :: ElabInfo
6767recinfo = EInfo [] emptyContext id Nothing Nothing id elabDecl'
6868
@@ -111,7 +111,7 @@ elabPrims = do mapM_ (elabDecl' EAll recinfo)
111111 elabBelieveMe
112112 = do let prim__believe_me = sUN "prim__believe_me"
113113 updateContext (addOperator prim__believe_me believeTy 3 p_believeMe)
114− -- The point is that it is believed to be total, even
114+ -- The point is that it is believed to be total, even
115115 -- though it clearly isn't :)
116116 setTotality prim__believe_me (Total [])
117117 i <- getIState
@@ -210,7 +210,7 @@ elabDecl' what info (PMutual f ps)
210210
211211 getDataDecls (PNamespace _ _ ds : decls)
212212 = getDataDecls ds ++ getDataDecls decls
213− getDataDecls (d : decls)
213+ getDataDecls (d : decls)
214214 | isDataDecl d = d : getDataDecls decls
215215 | otherwise = getDataDecls decls
216216 getDataDecls [] = []
src/Idris/Erasure.hs+16−15
@@ -32,7 +32,8 @@ import Data.IntMap (IntMap)
3232import Data.Text (pack)
3333import qualified Data.Text as T
3434
35−-- UseMap maps names to the set of used (reachable) argument positions.
35+-- | UseMap maps names to the set of used (reachable) argument
36+-- positions.
3637type UseMap = Map Name (IntMap (Set Reason))
3738
3839data Arg = Arg Int | Result deriving (Eq, Ord)
@@ -45,26 +46,26 @@ type Node = (Name, Arg)
4546type Deps = Map Cond DepSet
4647type Reason = (Name, Int) -- function name, argument index
4748
48−-- Nodes along with sets of reasons for every one.
49+-- | Nodes along with sets of reasons for every one.
4950type DepSet = Map Node (Set Reason)
5051
51−-- "Condition" is the conjunction
52−-- of elementary assumptions along the path from the root.
53−-- Elementary assumption (f, i) means that "function f uses the argument i".
52+-- | "Condition" is the conjunction of elementary assumptions along
53+-- the path from the root. Elementary assumption (f, i) means that
54+-- "function f uses the argument i".
5455type Cond = Set Node
5556
56−-- Variables carry certain information with them.
57+-- ^ Variables carry certain information with them.
5758data VarInfo = VI
58− { viDeps :: DepSet -- dependencies drawn in by the variable
59− , viFunArg :: Maybe Int -- which function argument this variable came from (defined only for patvars)
60− , viMethod :: Maybe Name -- name of the metamethod represented by the var, if any
59+ { viDeps :: DepSet -- ^ dependencies drawn in by the variable
60+ , viFunArg :: Maybe Int -- ^ which function argument this variable came from (defined only for patvars)
61+ , viMethod :: Maybe Name -- ^ name of the metamethod represented by the var, if any
6162 }
6263 deriving Show
6364
6465type Vars = Map Name VarInfo
6566
66−-- Perform usage analysis, write the relevant information in the internal
67−-- structures, returning the list of reachable names.
67+-- | Perform usage analysis, write the relevant information in the
68+-- internal structures, returning the list of reachable names.
6869performUsageAnalysis :: [Name] -> Idris [Name]
6970performUsageAnalysis startNames = do
7071 ctx <- tt_ctxt <$> getIState
@@ -137,7 +138,7 @@ performUsageAnalysis startNames = do
137138 fmt n rs = show n ++ " from " ++ intercalate ", " [show rn ++ " arg# " ++ show ri | (rn,ri) <- rs]
138139 warn = logErasure 0
139140
140−-- Find the minimal consistent usage by forward chaining.
141+-- | Find the minimal consistent usage by forward chaining.
141142minimalUsage :: Deps -> (Deps, (Set Name, UseMap))
142143minimalUsage = second gather . forwardChain
143144 where
@@ -160,8 +161,8 @@ forwardChain deps
160161 remove :: DepSet -> Deps -> Deps
161162 remove ds = M.mapKeysWith (M.unionWith S.union) (S.\\ M.keysSet ds)
162163
163−-- Build the dependency graph,
164−-- starting the depth-first search from a list of Names.
164+-- | Build the dependency graph, starting the depth-first search from
165+-- a list of Names.
165166buildDepMap :: Ctxt ClassInfo -> [(Name, Int)] -> [(Name, Int)] ->
166167 Context -> [Name] -> Deps
167168buildDepMap ci used externs ctx startNames
@@ -508,6 +509,6 @@ buildDepMap ci used externs ctx startNames
508509 unionMap :: (a -> Deps) -> [a] -> Deps
509510 unionMap f = M.unionsWith (M.unionWith S.union) . map f
510511
511−-- Make a field name out of a data constructor name and field number.
512+-- | Make a field name out of a data constructor name and field number.
512513mkFieldName :: Name -> Int -> Name
513514mkFieldName ctorName fieldNo = SN (WhereN fieldNo ctorName $ sMN fieldNo "field")
src/Idris/ErrReverse.hs+6−8
@@ -9,9 +9,8 @@ import Util.Pretty
99import Data.List
1010import Debug.Trace
1111
12−-- For display purposes, apply any 'error reversal' transformations so that
13−-- errors will be more readable
14−
12+-- | For display purposes, apply any 'error reversal' transformations
13+-- so that errors will be more readable
1514errReverse :: IState -> Term -> Term
1615errReverse ist t = rewrite 5 t -- (elideLambdas t)
1716 where
@@ -28,7 +27,7 @@ errReverse ist t = rewrite 5 t -- (elideLambdas t)
2827 -- the rule as invalid and return t)
2928
3029 applyNames ns t (Bind n (PVar ty) scl) (Bind n' (PVar ty') scr)
31− | n == n' = applyNames (n : ns) t (instantiate (P Ref n ty) scl)
30+ | n == n' = applyNames (n : ns) t (instantiate (P Ref n ty) scl)
3231 (instantiate (P Ref n' ty') scr)
3332 | otherwise = t
3433 applyNames ns t l r = matchTerm ns l r t
@@ -38,7 +37,7 @@ errReverse ist t = rewrite 5 t -- (elideLambdas t)
3837 matchTerm ns l r (App s f a) = let f' = matchTerm ns l r f
3938 a' = matchTerm ns l r a in
4039 App s f' a'
41− matchTerm ns l r (Bind n b sc) = let b' = fmap (matchTerm ns l r) b
40+ matchTerm ns l r (Bind n b sc) = let b' = fmap (matchTerm ns l r) b
4241 sc' = matchTerm ns l r sc in
4342 Bind n b' sc'
4443 matchTerm ns l r t = t
@@ -48,7 +47,7 @@ errReverse ist t = rewrite 5 t -- (elideLambdas t)
4847
4948 -- If any duplicate mappings, it's a failure
5049 combine [] = Just []
51− combine ((x, t) : xs)
50+ combine ((x, t) : xs)
5251 | Just _ <- lookup x xs = Nothing
5352 | otherwise = do xs' <- combine xs
5453 Just ((x, t) : xs')
@@ -64,9 +63,8 @@ errReverse ist t = rewrite 5 t -- (elideLambdas t)
6463 -- it as it won't be very enlightening.
6564
6665 elideLambdas (App s f a) = App s (elideLambdas f) (elideLambdas a)
67− elideLambdas (Bind n (Lam t) sc)
66+ elideLambdas (Bind n (Lam t) sc)
6867 | size sc > 200 = P Ref (sUN "...") Erased
6968 elideLambdas (Bind n b sc)
7069 = Bind n (fmap elideLambdas b) (elideLambdas sc)
7170 elideLambdas t = t
72−
src/Idris/Help.hs+16−16
@@ -1,21 +1,21 @@
11module Idris.Help (CmdArg(..), extraHelp) where
22
3−data CmdArg = ExprArg -- ^ The command takes an expression
4− | NameArg -- ^ The command takes a name
5− | FileArg -- ^ The command takes a file
6− | ModuleArg -- ^ The command takes a module name
7− | PkgArgs -- ^ The command takes a list of package names
8− | NumberArg -- ^ The command takes a number
9− | NamespaceArg -- ^ The command takes a namespace name
10− | OptionArg -- ^ The command takes an option
11− | MetaVarArg -- ^ The command takes a metavariable
12− | ColourArg -- ^ The command is the colour-setting command
13− | NoArg -- ^ No completion (yet!?)
14− | SpecialHeaderArg -- ^ do not use
15− | ConsoleWidthArg -- ^ The width of the console
16− | DeclArg -- ^ An Idris declaration, as might be contained in a file
17− | ManyArgs CmdArg -- ^ Zero or more of one kind of argument
18− | OptionalArg CmdArg -- ^ Zero or one of one kind of argument
3+data CmdArg = ExprArg -- ^ The command takes an expression
4+ | NameArg -- ^ The command takes a name
5+ | FileArg -- ^ The command takes a file
6+ | ModuleArg -- ^ The command takes a module name
7+ | PkgArgs -- ^ The command takes a list of package names
8+ | NumberArg -- ^ The command takes a number
9+ | NamespaceArg -- ^ The command takes a namespace name
10+ | OptionArg -- ^ The command takes an option
11+ | MetaVarArg -- ^ The command takes a metavariable
12+ | ColourArg -- ^ The command is the colour-setting command
13+ | NoArg -- ^ No completion (yet!?)
14+ | SpecialHeaderArg -- ^ do not use
15+ | ConsoleWidthArg -- ^ The width of the console
16+ | DeclArg -- ^ An Idris declaration, as might be contained in a file
17+ | ManyArgs CmdArg -- ^ Zero or more of one kind of argument
18+ | OptionalArg CmdArg -- ^ Zero or one of one kind of argument
1919 | SeqArgs CmdArg CmdArg -- ^ One kind of argument followed by another
2020
2121instance Show CmdArg where
src/Idris/IBC.hs+59−58
@@ -42,64 +42,64 @@ import Codec.Archive.Zip
4242ibcVersion :: Word16
4343ibcVersion = 143
4444
45−-- When IBC is being loaded - we'll load different things (and omit different
46−-- structures/definitions) depending on which phase we're in
47−data IBCPhase = IBC_Building -- ^ when building the module tree
48− | IBC_REPL Bool -- ^ when loading modules for the REPL
49− -- Bool = True for top level module
45+-- | When IBC is being loaded - we'll load different things (and omit
46+-- different structures/definitions) depending on which phase we're in.
47+data IBCPhase = IBC_Building -- ^ when building the module tree
48+ | IBC_REPL Bool -- ^ when loading modules for the REPL Bool = True for top level module
5049 deriving (Show, Eq)
5150
52−data IBCFile = IBCFile { ver :: Word16,
53− sourcefile :: FilePath,
54− ibc_reachablenames :: ![Name],
55− ibc_imports :: ![(Bool, FilePath)],
56− ibc_importdirs :: ![FilePath],
57− ibc_implicits :: ![(Name, [PArg])],
58− ibc_fixes :: ![FixDecl],
59− ibc_statics :: ![(Name, [Bool])],
60− ibc_classes :: ![(Name, ClassInfo)],
61− ibc_records :: ![(Name, RecordInfo)],
62− ibc_instances :: ![(Bool, Bool, Name, Name)],
63− ibc_dsls :: ![(Name, DSL)],
64− ibc_datatypes :: ![(Name, TypeInfo)],
65− ibc_optimise :: ![(Name, OptInfo)],
66− ibc_syntax :: ![Syntax],
67− ibc_keywords :: ![String],
68− ibc_objs :: ![(Codegen, FilePath)],
69− ibc_libs :: ![(Codegen, String)],
70− ibc_cgflags :: ![(Codegen, String)],
71− ibc_dynamic_libs :: ![String],
72− ibc_hdrs :: ![(Codegen, String)],
73− ibc_totcheckfail :: ![(FC, String)],
74− ibc_flags :: ![(Name, [FnOpt])],
75− ibc_fninfo :: ![(Name, FnInfo)],
76− ibc_cg :: ![(Name, CGInfo)],
77− ibc_docstrings :: ![(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))],
78− ibc_moduledocs :: ![(Name, Docstring D.DocTerm)],
79− ibc_transforms :: ![(Name, (Term, Term))],
80− ibc_errRev :: ![(Term, Term)],
81− ibc_coercions :: ![Name],
82− ibc_lineapps :: ![(FilePath, Int, PTerm)],
83− ibc_namehints :: ![(Name, Name)],
84− ibc_metainformation :: ![(Name, MetaInformation)],
85− ibc_errorhandlers :: ![Name],
86− ibc_function_errorhandlers :: ![(Name, Name, Name)], -- fn, arg, handler
87− ibc_metavars :: ![(Name, (Maybe Name, Int, [Name], Bool, Bool))],
88− ibc_patdefs :: ![(Name, ([([(Name, Term)], Term, Term)], [PTerm]))],
89− ibc_postulates :: ![Name],
90− ibc_externs :: ![(Name, Int)],
91− ibc_parsedSpan :: !(Maybe FC),
92− ibc_usage :: ![(Name, Int)],
93− ibc_exports :: ![Name],
94− ibc_autohints :: ![(Name, Name)],
95− ibc_deprecated :: ![(Name, String)],
96− ibc_defs :: ![(Name, Def)],
97− ibc_total :: ![(Name, Totality)],
98− ibc_injective :: ![(Name, Injectivity)],
99− ibc_access :: ![(Name, Accessibility)],
100− ibc_fragile :: ![(Name, String)]
101− }
102− deriving Show
51+data IBCFile = IBCFile {
52+ ver :: Word16
53+ , sourcefile :: FilePath
54+ , ibc_reachablenames :: ![Name]
55+ , ibc_imports :: ![(Bool, FilePath)]
56+ , ibc_importdirs :: ![FilePath]
57+ , ibc_implicits :: ![(Name, [PArg])]
58+ , ibc_fixes :: ![FixDecl]
59+ , ibc_statics :: ![(Name, [Bool])]
60+ , ibc_classes :: ![(Name, ClassInfo)]
61+ , ibc_records :: ![(Name, RecordInfo)]
62+ , ibc_instances :: ![(Bool, Bool, Name, Name)]
63+ , ibc_dsls :: ![(Name, DSL)]
64+ , ibc_datatypes :: ![(Name, TypeInfo)]
65+ , ibc_optimise :: ![(Name, OptInfo)]
66+ , ibc_syntax :: ![Syntax]
67+ , ibc_keywords :: ![String]
68+ , ibc_objs :: ![(Codegen, FilePath)]
69+ , ibc_libs :: ![(Codegen, String)]
70+ , ibc_cgflags :: ![(Codegen, String)]
71+ , ibc_dynamic_libs :: ![String]
72+ , ibc_hdrs :: ![(Codegen, String)]
73+ , ibc_totcheckfail :: ![(FC, String)]
74+ , ibc_flags :: ![(Name, [FnOpt])]
75+ , ibc_fninfo :: ![(Name, FnInfo)]
76+ , ibc_cg :: ![(Name, CGInfo)]
77+ , ibc_docstrings :: ![(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))]
78+ , ibc_moduledocs :: ![(Name, Docstring D.DocTerm)]
79+ , ibc_transforms :: ![(Name, (Term, Term))]
80+ , ibc_errRev :: ![(Term, Term)]
81+ , ibc_coercions :: ![Name]
82+ , ibc_lineapps :: ![(FilePath, Int, PTerm)]
83+ , ibc_namehints :: ![(Name, Name)]
84+ , ibc_metainformation :: ![(Name, MetaInformation)]
85+ , ibc_errorhandlers :: ![Name]
86+ , ibc_function_errorhandlers :: ![(Name, Name, Name)] -- fn, arg, handler
87+ , ibc_metavars :: ![(Name, (Maybe Name, Int, [Name], Bool, Bool))]
88+ , ibc_patdefs :: ![(Name, ([([(Name, Term)], Term, Term)], [PTerm]))]
89+ , ibc_postulates :: ![Name]
90+ , ibc_externs :: ![(Name, Int)]
91+ , ibc_parsedSpan :: !(Maybe FC)
92+ , ibc_usage :: ![(Name, Int)]
93+ , ibc_exports :: ![Name]
94+ , ibc_autohints :: ![(Name, Name)]
95+ , ibc_deprecated :: ![(Name, String)]
96+ , ibc_defs :: ![(Name, Def)]
97+ , ibc_total :: ![(Name, Totality)]
98+ , ibc_injective :: ![(Name, Injectivity)]
99+ , ibc_access :: ![(Name, Accessibility)]
100+ , ibc_fragile :: ![(Name, String)]
101+ }
102+ deriving Show
103103{-!
104104deriving instance Binary IBCFile
105105!-}
@@ -221,8 +221,9 @@ writeIBC src f
221221 (\c -> do logIBC 1 $ "Failed " ++ pshow i c)
222222 return ()
223223
224−-- Write a package index containing all the imports in the current IState
225−-- Used for ':search' of an entire package, to ensure everything is loaded.
224+-- | Write a package index containing all the imports in the current
225+-- IState Used for ':search' of an entire package, to ensure
226+-- everything is loaded.
226227writePkgIndex :: FilePath -> Idris ()
227228writePkgIndex f
228229 = do i <- getIState
src/Idris/Imports.hs+2−2
@@ -103,11 +103,11 @@ installedPackages = do
103103 goodDir idir d = any (".ibc" `isSuffixOf`) <$> allFilesInDir idir d
104104
105105
106−-- Case sensitive file existence check for Mac OS X.
106+-- | Case sensitive file existence check for Mac OS X.
107107doesFileExist' :: FilePath -> IO Bool
108108doesFileExist' = caseSensitive doesFileExist
109109
110−-- Case sensitive directory existence check for Mac OS X.
110+-- | Case sensitive directory existence check for Mac OS X.
111111doesDirectoryExist' :: FilePath -> IO Bool
112112doesDirectoryExist' = caseSensitive doesDirectoryExist
113113
src/Idris/Inliner.hs+2−4
@@ -8,8 +8,8 @@ import Idris.AbsSyntax
88inlineDef :: IState -> [([Name], Term, Term)] -> [([Name], Term, Term)]
99inlineDef ist ds = map (\ (ns, lhs, rhs) -> (ns, lhs, inlineTerm ist rhs)) ds
1010
11−-- Inlining is either top level (i.e. not in a function arg) or argument level
12−
11+-- | Inlining is either top level (i.e. not in a function arg) or argument level
12+--
1313-- For each application in a term:
1414-- * Check if the function is inlinable
1515-- (Dictionaries are inlinable in an argument, not otherwise)
@@ -17,7 +17,6 @@ inlineDef ist ds = map (\ (ns, lhs, rhs) -> (ns, lhs, inlineTerm ist rhs)) ds
1717-- + If successful, then continue on the result (top level)
1818-- + If not, reduce the arguments (argument level) and try again
1919-- - If not, inline all the arguments (top level)
20−
2120inlineTerm :: IState -> Term -> Term
2221inlineTerm ist tm = inl tm where
2322 inl orig@(P _ n _) = inlApp n [] orig
@@ -28,4 +27,3 @@ inlineTerm ist tm = inl tm where
2827 inl tm = tm
2928
3029 inlApp fn args orig = orig
31−
src/Idris/Parser.hs+42−43
@@ -89,7 +89,7 @@ import System.IO
8989
9090{- * Main grammar -}
9191
92−{- | Parses module definition
92+{-| Parses module definition
9393
9494@
9595 ModuleHeader ::= DocComment_t? 'module' Identifier_t ';'?;
@@ -122,7 +122,7 @@ data ImportInfo = ImportInfo { import_reexport :: Bool
122122 , import_modname_location :: FC
123123 }
124124
125−{- | Parses an import statement
125+{-| Parses an import statement
126126
127127@
128128 Import ::= 'import' Identifier_t ';'?;
@@ -144,7 +144,7 @@ import_ = do fc <- getFC
144144 where ns = Spl.splitOn "."
145145 toPath = foldl1' (</>) . ns
146146
147−{- | Parses program source
147+{-| Parses program source
148148
149149@
150150 Prog ::= Decl* EOF;
@@ -238,7 +238,7 @@ internalDecl syn
238238 continue False (PClauses _ _ _ _) = True
239239 continue c _ = c
240240
241−{- | Parses a top-level declaration with possible syntax sugar
241+{-| Parses a top-level declaration with possible syntax sugar
242242
243243@
244244Decl' ::=
@@ -387,7 +387,7 @@ declExtension syn ns rules =
387387 highlightP fc AnnKeyword
388388 return Nothing
389389
390−{- | Parses a syntax extension declaration (and adds the rule to parser state)
390+{-| Parses a syntax extension declaration (and adds the rule to parser state)
391391
392392@
393393 SyntaxDecl ::= SyntaxRule;
@@ -418,7 +418,7 @@ addReplSyntax i s = i { syntax_rules = updateSyntaxRules [s] rs,
418418 ns = syntax_keywords i
419419 ks = map show (syntaxNames s)
420420
421−{- | Parses a syntax extension declaration
421+{-| Parses a syntax extension declaration
422422
423423@
424424SyntaxRuleOpts ::= 'term' | 'pattern';
@@ -545,7 +545,7 @@ syntaxRule syn
545545 put ist { idris_name = idx + 1 }
546546 return $ sMN idx (show n)
547547
548−{- | Parses a syntax symbol (either binding variable, keyword or expression)
548+{-| Parses a syntax symbol (either binding variable, keyword or expression)
549549
550550@
551551SyntaxSym ::= '[' Name_t ']'
@@ -566,7 +566,7 @@ syntaxSym = try (do lchar '['; n <- fst <$> name; lchar ']'
566566 return (Symbol sym)
567567 <?> "syntax symbol"
568568
569−{- | Parses a function declaration with possible syntax sugar
569+{-| Parses a function declaration with possible syntax sugar
570570
571571@
572572 FunDecl ::= FunDecl';
@@ -715,7 +715,7 @@ fnOpt = do reservedHL "total"; return TotalFn
715715 return (Just (fromInteger reds)))
716716 return (n, t)
717717
718−{- | Parses a postulate
718+{-| Parses a postulate
719719
720720@
721721Postulate ::=
@@ -742,7 +742,8 @@ postulate syn = do (doc, ext)
742742 <?> "postulate"
743743 where ppostDecl = do fc <- reservedHL "postulate"; return False
744744 <|> do lchar '%'; reserved "extern"; return True
745−{- | Parses a using declaration
745+
746+{-| Parses a using declaration
746747
747748@
748749Using ::=
@@ -761,14 +762,14 @@ using_ syn =
761762 return (concat ds)
762763 <?> "using declaration"
763764
764−{- | Parses a parameters declaration
765+{-| Parses a parameters declaration
765766
766767@
767768Params ::=
768769 'parameters' '(' TypeDeclList ')' OpenBlock Decl* CloseBlock
769770 ;
770771@
771− -}
772+-}
772773params :: SyntaxInfo -> IdrisParser [PDecl]
773774params syn =
774775 do reservedHL "parameters"; lchar '('; ns <- typeDeclList syn; lchar ')'
@@ -781,10 +782,7 @@ params syn =
781782 return [PParams fc ns' (concat ds)]
782783 <?> "parameters declaration"
783784
784−{- | Parses an open block
785−
786−-}
787−
785+-- | Parses an open block
788786openInterface :: SyntaxInfo -> IdrisParser [PDecl]
789787openInterface syn =
790788 do reservedHL "using"
@@ -799,9 +797,10 @@ openInterface syn =
799797 <?> "open interface declaration"
800798
801799
800+
802801
803802
804−{- | Parses a mutual declaration (for mutually recursive functions)
803+{-| Parses a mutual declaration (for mutually recursive functions)
805804
806805@
807806Mutual ::=
@@ -838,7 +837,7 @@ namespace syn =
838837 return [PNamespace n nfc (concat ds)]
839838 <?> "namespace declaration"
840839
841−{- | Parses a methods block (for instances)
840+{-| Parses a methods block (for instances)
842841
843842@
844843 InstanceBlock ::= 'where' OpenBlock FnDecl* CloseBlock
@@ -852,7 +851,7 @@ instanceBlock syn = do reservedHL "where"
852851 return (concat ds)
853852 <?> "implementation block"
854853
855−{- | Parses a methods and instances block (for type classes)
854+{-| Parses a methods and instances block (for type classes)
856855
857856@
858857MethodOrInstance ::=
@@ -941,7 +940,7 @@ class_ syn = do (doc, argDocs, acc)
941940 fc <- getFC
942941 return (i, ifc, PType fc)
943942
944−{- | Parses a type class instance declaration
943+{-| Parses a type class instance declaration
945944
946945@
947946 Instance ::=
@@ -1003,7 +1002,7 @@ docstring syn = do (doc, argDocs) <- option noDocs docComment
10031002 return (doc', argDocs')
10041003
10051004
1006−{- | Parses a using declaration list
1005+{-| Parses a using declaration list
10071006
10081007@
10091008UsingDeclList ::=
@@ -1035,7 +1034,7 @@ usingDeclList syn
10351034 return (map (\x -> UImplicit x t) ns)
10361035 <?> "using declaration list"
10371036
1038−{- |Parses a using declaration
1037+{-| Parses a using declaration
10391038
10401039@
10411040UsingDecl ::=
@@ -1054,7 +1053,7 @@ usingDecl syn = try (do x <- fst <$> fnName
10541053 return (UConstraint c xs)
10551054 <?> "using declaration"
10561055
1057−{- | Parse a clause with patterns
1056+{-| Parse a clause with patterns
10581057
10591058@
10601059Pattern ::= Clause;
@@ -1066,7 +1065,7 @@ pattern syn = do fc <- getFC
10661065 return (PClauses fc [] (sMN 2 "_") [clause]) -- collect together later
10671066 <?> "pattern"
10681067
1069−{- | Parse a constant applicative form declaration
1068+{-| Parse a constant applicative form declaration
10701069
10711070@
10721071CAF ::= 'let' FnName '=' Expr Terminator;
@@ -1083,7 +1082,7 @@ caf syn = do reservedHL "let"
10831082 return (PCAF fc n t)
10841083 <?> "constant applicative form declaration"
10851084
1086−{- | Parse an argument expression
1085+{-| Parse an argument expression
10871086
10881087@
10891088ArgExpr ::= HSimpleExpr | {- In Pattern External (User-defined) Expression -};
@@ -1094,7 +1093,7 @@ argExpr syn = let syn' = syn { inPattern = True } in
10941093 try (hsimpleExpr syn') <|> simpleExternalExpr syn'
10951094 <?> "argument expression"
10961095
1097−{- | Parse a right hand side of a function
1096+{-| Parse a right hand side of a function
10981097
10991098@
11001099RHS ::= '=' Expr
@@ -1130,7 +1129,7 @@ rhs syn n = do lchar '='; expr syn
11301129 where addLetC (l, r) = (l, addLet fc nm r)
11311130 addLet fc nm r = (PLet fc (sUN "value") NoFC Placeholder r (PMetavar NoFC nm))
11321131
1133−{- |Parses a function clause
1132+{-|Parses a function clause
11341133
11351134@
11361135RHSOrWithBlock ::= RHS WhereOrTerminator
@@ -1296,7 +1295,7 @@ wExpr syn = do lchar '|'
12961295 expr' (syn { inPattern = True })
12971296 <?> "with pattern"
12981297
1299−{- | Parses a where block
1298+{-| Parses a where block
13001299
13011300@
13021301WhereBlock ::= 'where' OpenBlock Decl+ CloseBlock;
@@ -1310,7 +1309,7 @@ whereBlock n syn
13101309 return (concat ds, map (\x -> (x, decoration syn x)) dns)
13111310 <?> "where block"
13121311
1313−{- |Parses a code generation target language name
1312+{-|Parses a code generation target language name
13141313
13151314@
13161315Codegen ::= 'C'
@@ -1328,7 +1327,7 @@ codegen_ = do n <- fst <$> identifier
13281327 <|> do reserved "Bytecode"; return Bytecode
13291328 <?> "code generation language"
13301329
1331−{- |Parses a compiler directive
1330+{-|Parses a compiler directive
13321331@
13331332StringList ::=
13341333 String
@@ -1433,7 +1432,7 @@ pLangExt :: IdrisParser LanguageExt
14331432pLangExt = (reserved "TypeProviders" >> return TypeProviders)
14341433 <|> (reserved "ErrorReflection" >> return ErrorReflection)
14351434
1436−{- | Parses a totality
1435+{-| Parses a totality
14371436
14381437@
14391438Totality ::= 'partial' | 'total' | 'covering'
@@ -1446,7 +1445,7 @@ totality
14461445 <|> do reservedHL "partial"; return DefaultCheckingPartial
14471446 <|> do reservedHL "covering"; return DefaultCheckingCovering
14481447
1449−{- | Parses a type provider
1448+{-| Parses a type provider
14501449
14511450@
14521451Provider ::= DocComment_t? '%' 'provide' Provider_What? '(' FnName TypeSig ')' 'with' Expr;
@@ -1476,7 +1475,7 @@ provider syn = do doc <- try (do (doc, _) <- docstring syn
14761475 e <- expr syn <?> "provider expression"
14771476 return [PProvider doc syn fc nfc (ProvPostulate e) n]
14781477
1479−{- | Parses a transform
1478+{-| Parses a transform
14801479
14811480@
14821481Transform ::= '%' 'transform' Expr '==>' Expr
@@ -1495,7 +1494,7 @@ transform syn = do try (lchar '%' *> reserved "transform")
14951494 return [PTransform fc False l r]
14961495 <?> "transform"
14971496
1498−{- | Parses a top-level reflected elaborator script
1497+{-| Parses a top-level reflected elaborator script
14991498
15001499@
15011500RunElabDecl ::= '%' 'runElab' Expr
@@ -1513,19 +1512,19 @@ runElabDecl syn =
15131512 <?> "top-level elaborator script"
15141513
15151514{- * Loading and parsing -}
1516−{- | Parses an expression from input -}
1515+{-| Parses an expression from input -}
15171516parseExpr :: IState -> String -> Result PTerm
15181517parseExpr st = runparser (fullExpr defaultSyntax) st "(input)"
15191518
1520−{- | Parses a constant form input -}
1519+{-| Parses a constant form input -}
15211520parseConst :: IState -> String -> Result Const
15221521parseConst st = runparser (fmap fst constant) st "(input)"
15231522
1524−{- | Parses a tactic from input -}
1523+{-| Parses a tactic from input -}
15251524parseTactic :: IState -> String -> Result PTactic
15261525parseTactic st = runparser (fullTactic defaultSyntax) st "(input)"
15271526
1528−{- | Parses a do-step from input (used in the elab shell) -}
1527+{-| Parses a do-step from input (used in the elab shell) -}
15291528parseElabShellStep :: IState -> String -> Result (Either ElabShellCmd PDo)
15301529parseElabShellStep ist = runparser (fmap Right (do_ defaultSyntax) <|> fmap Left elabShellCmd) ist "(input)"
15311530 where elabShellCmd = char ':' >>
@@ -1639,7 +1638,7 @@ parseProg syn fname input mrk
16391638 i' <- get
16401639 return (ds, i')
16411640
1642−{- | Load idris module and show error if something wrong happens -}
1641+{-| Load idris module and show error if something wrong happens -}
16431642loadModule :: FilePath -> IBCPhase -> Idris (Maybe String)
16441643loadModule f phase
16451644 = idrisCatch (loadModule' f phase)
@@ -1648,7 +1647,7 @@ loadModule f phase
16481647 iWarn (getErrSpan e) $ pprintErr ist e
16491648 return Nothing)
16501649
1651−{- | Load idris module -}
1650+{-| Load idris module -}
16521651loadModule' :: FilePath -> IBCPhase -> Idris (Maybe String)
16531652loadModule' f phase
16541653 = do i <- getIState
@@ -1671,7 +1670,7 @@ loadModule' f phase
16711670 LIDR sfn -> loadSource True sfn Nothing)
16721671 return $ Just file
16731672
1674−{- | Load idris code from file -}
1673+{-| Load idris code from file -}
16751674loadFromIFile :: Bool -> IBCPhase -> IFileType -> Maybe Int -> Idris ()
16761675loadFromIFile reexp phase i@(IBC fn src) maxline
16771676 = do logParser 1 $ "Skipping " ++ getSrcFile i
@@ -1695,7 +1694,7 @@ loadSource' lidr r maxline
16951694 At f e' -> iWarn f (pprintErr ist e')
16961695 _ -> iWarn (getErrSpan e) (pprintErr ist e))
16971696
1698−{- | Load Idris source code-}
1697+{-| Load Idris source code-}
16991698loadSource :: Bool -> FilePath -> Maybe Int -> Idris ()
17001699loadSource lidr f toline
17011700 = do logParser 1 ("Reading " ++ f)
@@ -1878,7 +1877,7 @@ loadSource lidr f toline
18781877 docName = NS modDocName (map T.pack (reverse mname))
18791878 parsedDocs ist = annotCode (tryFullExpr syn ist) docs
18801879
1881−{- | Adds names to hide list -}
1880+{-| Adds names to hide list -}
18821881addHides :: Ctxt Accessibility -> Idris ()
18831882addHides xs = do i <- getIState
18841883 let defh = default_access i
src/Idris/Parser/Data.hs+1−1
@@ -37,7 +37,7 @@ import qualified Data.ByteString.UTF8 as UTF8
3737
3838import Debug.Trace
3939
40−{- |Parses a record type declaration
40+{- | Parses a record type declaration
4141Record ::=
4242 DocComment Accessibility? 'record' FnName TypeSig 'where' OpenBlock Constructor KeepTerminator CloseBlock;
4343-}
src/Idris/PartialEval.hs+51−46
@@ -27,11 +27,12 @@ data PEArgType = ImplicitS -- ^ Implicit static argument
2727-- | A partially evaluated function. pe_app captures the lhs of the
2828-- new definition, pe_def captures the rhs, and pe_clauses is the
2929-- specialised implementation.
30−-- pe_simple is set if the result is always reducible, because in such a
31−-- case we'll also need to reduce the static argument
30+--
31+-- pe_simple is set if the result is always reducible, because in such
32+-- a case we'll also need to reduce the static argument
3233data PEDecl = PEDecl { pe_app :: PTerm, -- new application
3334 pe_def :: PTerm, -- old application
34− pe_clauses :: [(PTerm, PTerm)], -- clauses of new application
35+ pe_clauses :: [(PTerm, PTerm)], -- clauses of new application
3536 pe_simple :: Bool -- if just one reducible clause
3637 }
3738
@@ -42,14 +43,14 @@ data PEDecl = PEDecl { pe_app :: PTerm, -- new application
4243-- must have reduced at least once.
4344-- If we don't do this, we might end up making an infinite function after
4445-- applying the transformation.
45−partial_eval :: Context ->
46− [(Name, Maybe Int)] ->
47− [Either Term (Term, Term)] ->
48− Maybe [Either Term (Term, Term)]
46+partial_eval :: Context
47+ -> [(Name, Maybe Int)]
48+ -> [Either Term (Term, Term)]
49+ -> Maybe [Either Term (Term, Term)]
4950partial_eval ctxt ns_in tms = mapM peClause tms where
5051 ns = squash ns_in
51− squash ((n, Just x) : ns)
52− | Just (Just y) <- lookup n ns
52+ squash ((n, Just x) : ns)
53+ | Just (Just y) <- lookup n ns
5354 = squash ((n, Just (x + y)) : drop n ns)
5455 | otherwise = (n, Just x) : squash ns
5556 squash (n : ns) = n : squash ns
@@ -58,7 +59,7 @@ partial_eval ctxt ns_in tms = mapM peClause tms where
5859 drop n ((m, _) : ns) | n == m = ns
5960 drop n (x : ns) = x : drop n ns
6061 drop n [] = []
61−
62+
6263 -- If the term is not a clause, it is simply kept as is
6364 peClause (Left t) = Just $ Left t
6465 -- If the term is a clause, specialise the right hand side
@@ -68,7 +69,7 @@ partial_eval ctxt ns_in tms = mapM peClause tms where
6869 return (Right (lhs, rhs'))
6970
7071 -- TMP HACK until I do PE by WHNF rather than using main evaluator
71− toLimit (n, Nothing) | isTCDict n ctxt = (n, 2)
72+ toLimit (n, Nothing) | isTCDict n ctxt = (n, 2)
7273 toLimit (n, Nothing) = (n, 65536) -- somewhat arbitrary reduction limit
7374 toLimit (n, Just l) = (n, l)
7475
@@ -103,7 +104,7 @@ specType args ty = let (t, args') = runState (unifyEq args ty) [] in
103104 unifyEq (imp@(ImplicitD, v) : xs) (Bind n (Pi i t k) sc)
104105 = do amap <- get
105106 case lookup imp amap of
106− Just n' ->
107+ Just n' ->
107108 do put (amap ++ [((UnifiedD, Erased), n)])
108109 sc' <- unifyEq xs (subst n (P Bound n' Erased) sc)
109110 return (Bind n (Pi i t k) sc') -- erase later
@@ -119,12 +120,12 @@ specType args ty = let (t, args') = runState (unifyEq args ty) [] in
119120 put (args ++ (zip xs (repeat (sUN "_"))))
120121 return t
121122
122−-- | Creates an Idris type declaration given current state and a
123+-- | Creates an Idris type declaration given current state and a
123124-- specialised TT function application type.
124125-- Can be used in combination with the output of 'specType'.
125126--
126127-- This should: specialise any static argument position, then generalise
127−-- over any function applications in the result.
128+-- over any function applications in the result.
128129mkPE_TyDecl :: IState -> [(PEArgType, Term)] -> Type -> PTerm
129130mkPE_TyDecl ist args ty = mkty args ty
130131 where
@@ -132,7 +133,7 @@ mkPE_TyDecl ist args ty = mkty args ty
132133 = PPi expl n NoFC (delab ist (generaliseIn t)) (mkty xs sc)
133134 mkty ((ImplicitD, v) : xs) (Bind n (Pi _ t k) sc)
134135 | concreteClass ist t = mkty xs sc
135− | classConstraint ist t
136+ | classConstraint ist t
136137 = PPi constraint n NoFC (delab ist (generaliseIn t)) (mkty xs sc)
137138 | otherwise = PPi impl n NoFC (delab ist (generaliseIn t)) (mkty xs sc)
138139
@@ -141,7 +142,7 @@ mkPE_TyDecl ist args ty = mkty args ty
141142 mkty [] t = delab ist t
142143
143144 generaliseIn tm = evalState (gen tm) 0
144−
145+
145146 gen tm | (P _ fn _, args) <- unApply tm,
146147 isFnName fn (tt_ctxt ist)
147148 = do nm <- get
@@ -166,26 +167,26 @@ concreteClass ist v
166167 | (P _ c _, args) <- unApply v = all concrete args
167168 | otherwise = False
168169 where concrete (Constant _) = True
169− concrete tm | (P _ n _, args) <- unApply tm
170+ concrete tm | (P _ n _, args) <- unApply tm
170171 = case lookupTy n (tt_ctxt ist) of
171172 [_] -> all concrete args
172173 _ -> False
173174 | otherwise = False
174175
175−mkNewPats :: IState ->
176− [(Term, Term)] -> -- definition to specialise
177− [(PEArgType, Term)] -> -- arguments to specialise with
178− Name -> -- New name
179− Name -> -- Specialised function name
180− PTerm -> -- Default lhs
181− PTerm -> -- Default rhs
182− PEDecl
176+mkNewPats :: IState
177+ -> [(Term, Term)] -- ^ definition to specialise
178+ -> [(PEArgType, Term)] -- ^ arguments to specialise with
179+ -> Name -- ^ New name
180+ -> Name -- ^ Specialised function name
181+ -> PTerm -- ^ Default lhs
182+ -> PTerm -- ^ Default rhs
183+ -> PEDecl
183184-- If all of the dynamic positions on the lhs are variables (rather than
184185-- patterns or constants) then we can just make a simple definition
185186-- directly applying the specialised function, since we know the
186187-- definition isn't going to block on any of the dynamic arguments
187188-- in this case
188−mkNewPats ist d ns newname sname lhs rhs | all dynVar (map fst d)
189+mkNewPats ist d ns newname sname lhs rhs | all dynVar (map fst d)
189190 = PEDecl lhs rhs [(lhs, rhs)] True
190191 where dynVar ap = case unApply ap of
191192 (_, args) -> dynArgs ns args
@@ -197,32 +198,32 @@ mkNewPats ist d ns newname sname lhs rhs | all dynVar (map fst d)
197198 -- do some more work
198199 dynArgs (_ : ns) (V _ : as) = dynArgs ns as
199200 dynArgs (_ : ns) (P _ _ _ : as) = dynArgs ns as
200− dynArgs _ _ = False -- and now we'll get stuck
201+ dynArgs _ _ = False -- and now we'll get stuck
201202
202203mkNewPats ist d ns newname sname lhs rhs =
203204 PEDecl lhs rhs (map mkClause d) False
204− where
205+ where
205206 mkClause :: (Term, Term) -> (PTerm, PTerm)
206207 mkClause (oldlhs, oldrhs)
207− = let (_, as) = unApply oldlhs
208+ = let (_, as) = unApply oldlhs
208209 lhsargs = mkLHSargs [] ns as
209210 lhs = PApp emptyFC (PRef emptyFC [] newname) lhsargs
210− rhs = PApp emptyFC (PRef emptyFC [] sname)
211+ rhs = PApp emptyFC (PRef emptyFC [] sname)
211212 (mkRHSargs ns lhsargs) in
212213 (lhs, rhs)
213214
214215 mkLHSargs _ [] _ = []
215216 -- dynamics don't appear if they're implicit
216− mkLHSargs sub ((ExplicitD, t) : ns) (a : as)
217+ mkLHSargs sub ((ExplicitD, t) : ns) (a : as)
217218 = pexp (delab ist (substNames sub a)) : mkLHSargs sub ns as
218− mkLHSargs sub ((ImplicitD, _) : ns) (a : as)
219+ mkLHSargs sub ((ImplicitD, _) : ns) (a : as)
219220 = mkLHSargs sub ns as
220− mkLHSargs sub ((UnifiedD, _) : ns) (a : as)
221+ mkLHSargs sub ((UnifiedD, _) : ns) (a : as)
221222 = mkLHSargs sub ns as
222223 -- statics get dropped in any case
223− mkLHSargs sub ((ImplicitS, t) : ns) (a : as)
224+ mkLHSargs sub ((ImplicitS, t) : ns) (a : as)
224225 = mkLHSargs (extend a t sub) ns as
225− mkLHSargs sub ((ExplicitS, t) : ns) (a : as)
226+ mkLHSargs sub ((ExplicitS, t) : ns) (a : as)
226227 = mkLHSargs (extend a t sub) ns as
227228 mkLHSargs sub _ [] = [] -- no more LHS
228229
@@ -237,20 +238,23 @@ mkNewPats ist d ns newname sname lhs rhs =
237238 mkSubst :: (Term, Term) -> Maybe (Name, Term)
238239 mkSubst (P _ n _, t) = Just (n, t)
239240 mkSubst _ = Nothing
240−
241+
241242-- | Creates a new declaration for a specialised function application.
242243-- Simple version at the moment: just create a version which is a direct
243244-- application of the function to be specialised.
244245-- More complex version to do: specialise the definition clause by clause
245−mkPE_TermDecl :: IState -> Name -> Name ->
246− [(PEArgType, Term)] -> PEDecl
247−mkPE_TermDecl ist newname sname ns
248− = let lhs = PApp emptyFC (PRef emptyFC [] newname) (map pexp (mkp ns))
249− rhs = eraseImps $ delab ist (mkApp (P Ref sname Erased) (map snd ns))
246+mkPE_TermDecl :: IState
247+ -> Name
248+ -> Name
249+ -> [(PEArgType, Term)]
250+ -> PEDecl
251+mkPE_TermDecl ist newname sname ns
252+ = let lhs = PApp emptyFC (PRef emptyFC [] newname) (map pexp (mkp ns))
253+ rhs = eraseImps $ delab ist (mkApp (P Ref sname Erased) (map snd ns))
250254 patdef = lookupCtxtExact sname (idris_patdefs ist)
251255 newpats = case patdef of
252256 Nothing -> PEDecl lhs rhs [(lhs, rhs)] True
253− Just d -> mkNewPats ist (getPats d) ns
257+ Just d -> mkNewPats ist (getPats d) ns
254258 newname sname lhs rhs in
255259 newpats where
256260
@@ -269,8 +273,10 @@ mkPE_TermDecl ist newname sname ns
269273 deImpArg a = a
270274
271275-- | Get specialised applications for a given function
272−getSpecApps :: IState -> [Name] -> Term ->
273− [(Name, [(PEArgType, Term)])]
276+getSpecApps :: IState
277+ -> [Name]
278+ -> Term
279+ -> [(Name, [(PEArgType, Term)])]
274280getSpecApps ist env tm = ga env (explicitNames tm) where
275281
276282-- staticArg env True _ tm@(P _ n _) _ | n `elem` env = Just (True, tm)
@@ -326,7 +332,7 @@ getSpecApps ist env tm = ga env (explicitNames tm) where
326332
327333 -- There's an overlap if the case tree has a default case along with
328334 -- some other cases. It's fine if there's a default case on its own.
329− noOverlapAlts (ConCase _ _ _ sc : rest)
335+ noOverlapAlts (ConCase _ _ _ sc : rest)
330336 = noOverlapAlts rest && noOverlap sc
331337 noOverlapAlts (FnCase _ _ sc : rest) = noOverlapAlts rest
332338 noOverlapAlts (ConstCase _ sc : rest)
@@ -335,4 +341,3 @@ getSpecApps ist env tm = ga env (explicitNames tm) where
335341 = noOverlapAlts rest && noOverlap sc
336342 noOverlapAlts (DefaultCase _ : _) = False
337343 noOverlapAlts _ = True
338−
src/Idris/ProofSearch.hs+21−19
@@ -113,17 +113,18 @@ cantSolveGoal = do g <- goal
113113 lift $ tfail $
114114 CantSolveGoal g (map (\(n,b) -> (n, binderTy b)) env)
115115
116−proofSearch :: Bool -> -- recursive search (False for 'refine')
117− Bool -> -- invoked from a tactic proof. If so, making
118− -- new metavariables is meaningless, and there shoudl
119− -- be an error reported instead.
120− Bool -> -- ambiguity ok
121− Bool -> -- defer on failure
122− Int -> -- maximum depth
123− (PTerm -> ElabD ()) -> Maybe Name -> Name ->
124− [Name] ->
125− [Name] ->
126− IState -> ElabD ()
116+proofSearch :: Bool -- ^ recursive search (False for 'refine')
117+ -> Bool -- ^ invoked from a tactic proof. If so, making new metavariables is meaningless, and there should be an error reported instead.
118+ -> Bool -- ^ ambiguity ok
119+ -> Bool -- ^ defer on failure
120+ -> Int -- ^ maximum depth
121+ -> (PTerm -> ElabD ())
122+ -> Maybe Name
123+ -> Name
124+ -> [Name]
125+ -> [Name]
126+ -> IState
127+ -> ElabD ()
127128proofSearch False fromProver ambigok deferonfail depth elab _ nroot psnames [fn] ist
128129 = do -- get all possible versions of the name, take the first one that
129130 -- works
@@ -336,13 +337,14 @@ proofSearch rec fromProver ambigok deferonfail maxDepth elab fn nroot psnames hi
336337 (Bind _ (Pi _ _ _) _) -> [TextPart "In particular, function types are not supported."]
337338 _ -> []
338339
339−-- | Resolve interfaces. This will only pick up 'normal' implementations, never
340−-- named implementations (which is enforced by 'findInstances').
341−resolveTC :: Bool -- ^ using default Int
342− -> Bool -- ^ allow open implementations
343− -> Int -- ^ depth
344− -> Term -- ^ top level goal, for error messages
345− -> Name -- ^ top level function name, to prevent loops
340+-- | Resolve interfaces. This will only pick up 'normal'
341+-- implementations, never named implementations (which is enforced by
342+-- 'findInstances').
343+resolveTC :: Bool -- ^ using default Int
344+ -> Bool -- ^ allow open implementations
345+ -> Int -- ^ depth
346+ -> Term -- ^ top level goal, for error messages
347+ -> Name -- ^ top level function name, to prevent loops
346348 -> (PTerm -> ElabD ()) -- ^ top level elaborator
347349 -> IState -> ElabD ()
348350resolveTC def openOK depth top fn elab ist
@@ -392,7 +394,7 @@ resTC' tcs defaultOn openOK topholes depth topg fn elab ist
392394 try' (trivialTCs okholes elab ist)
393395 (do addDefault t tc ttypes
394396 let stk = map fst (filter snd $ elab_stack ist)
395− let insts = idris_openimpls ist ++ findInstances ist t
397+ let insts = idris_openimpls ist ++ findInstances ist t
396398 blunderbuss t depth stk (stk ++ insts)) True
397399
398400 -- returns Just hs if okay, where hs are holes which are okay in the
src/Idris/Transforms.hs+17−19
@@ -1,6 +1,6 @@
11{-# LANGUAGE PatternGuards #-}
22
3−module Idris.Transforms(transformPats,
3+module Idris.Transforms(transformPats,
44 transformPatsWith,
55 applyTransRulesWith,
66 applyTransRules) where
@@ -27,23 +27,23 @@ transformPatsWith rs ps = map tClause ps where
2727 = let rhs' = applyTransRulesWith rs rhs in
2828 Right (lhs, rhs')
2929
30−-- Work on explicitly named terms, so we don't have to manipulate
31−-- de Bruijn indices
30+-- | Work on explicitly named terms, so we don't have to manipulate de
31+-- Bruijn indices
3232applyTransRules :: IState -> Term -> Term
3333applyTransRules ist tm = finalise $ applyAll [] (idris_transforms ist) (vToP tm)
3434
35−-- Work on explicitly named terms, so we don't have to manipulate
36−-- de Bruijn indices
35+-- | Work on explicitly named terms, so we don't have to manipulate de
36+-- Bruijn indices
3737applyTransRulesWith :: [(Term, Term)] -> Term -> Term
38−applyTransRulesWith rules tm
38+applyTransRulesWith rules tm
3939 = finalise $ applyAll rules emptyContext (vToP tm)
4040
4141applyAll :: [(Term, Term)] -> Ctxt [(Term, Term)] -> Term -> Term
42−applyAll extra ts ap@(App s f a)
42+applyAll extra ts ap@(App s f a)
4343 | (P _ fn ty, args) <- unApply ap
4444 = let rules = case lookupCtxtExact fn ts of
4545 Just r -> extra ++ r
46− Nothing -> extra
46+ Nothing -> extra
4747 ap' = App s (applyAll extra ts f) (applyAll extra ts a) in
4848 case rules of
4949 [] -> ap'
@@ -52,9 +52,9 @@ applyAll extra ts ap@(App s f a)
5252 App s (applyAll extra ts f')
5353 (applyAll extra ts a')
5454 Just tm' -> tm'
55− _ -> App s (applyAll extra ts f)
55+ _ -> App s (applyAll extra ts f)
5656 (applyAll extra ts a)
57−applyAll extra ts (Bind n b sc) = Bind n (fmap (applyAll extra ts) b)
57+applyAll extra ts (Bind n b sc) = Bind n (fmap (applyAll extra ts) b)
5858 (applyAll extra ts sc)
5959applyAll extra ts t = t
6060
@@ -64,11 +64,11 @@ applyFnRules (r : rs) tm | Just tm' <- applyRule r tm = Just tm'
6464 | otherwise = applyFnRules rs tm
6565
6666applyRule :: (Term, Term) -> Term -> Maybe Term
67−applyRule (lhs, rhs) tm
68− | Just ms <- matchTerm lhs tm
67+applyRule (lhs, rhs) tm
68+ | Just ms <- matchTerm lhs tm
6969-- = trace ("SUCCESS " ++ show ms ++ "\n FROM\n" ++ show lhs ++
70−-- "\n" ++ show rhs
71−-- ++ "\n" ++ show tm ++ " GIVES\n" ++ show (depat ms rhs)) $
70+-- "\n" ++ show rhs
71+-- ++ "\n" ++ show tm ++ " GIVES\n" ++ show (depat ms rhs)) $
7272 = Just $ depat ms rhs
7373 | otherwise = Nothing
7474-- ASSUMPTION: The names in the transformation rule bindings cannot occur
@@ -76,7 +76,7 @@ applyRule (lhs, rhs) tm
7676-- (In general, this would not be true, but when we elaborate transformation
7777-- rules we mangle the names so that it is true. While this feels a bit
7878-- hacky, it's much easier to think about than mangling de Bruijn indices).
79− where depat ms (Bind n (PVar t) sc)
79+ where depat ms (Bind n (PVar t) sc)
8080 = case lookup n ms of
8181 Just tm -> depat ms (subst n tm sc)
8282 _ -> depat ms sc -- no occurrence? Shouldn't happen
@@ -85,9 +85,9 @@ applyRule (lhs, rhs) tm
8585matchTerm :: Term -> Term -> Maybe [(Name, Term)]
8686matchTerm lhs tm = matchVars [] lhs tm
8787 where
88− matchVars acc (Bind n (PVar t) sc) tm
88+ matchVars acc (Bind n (PVar t) sc) tm
8989 = matchVars (n : acc) (instantiate (P Bound n t) sc) tm
90− matchVars acc sc tm
90+ matchVars acc sc tm
9191 = -- trace (show acc ++ ": " ++ show (sc, tm)) $
9292 doMatch acc sc tm
9393
@@ -100,5 +100,3 @@ matchTerm lhs tm = matchVars [] lhs tm
100100 return (fm ++ am)
101101 doMatch ns x y | vToP x == vToP y = return []
102102 | otherwise = Nothing
103−
104−