@@ -626,8 +626,8 @@ elabPrims = do mapM_ (elabDecl EAll toplevel)
626626
627627
628628-- | Elaborate a type provider
629−elabProvider :: ElabInfo -> SyntaxInfo -> FC -> Name -> PTerm -> PTerm -> Idris ()
630−elabProvider info syn fc n ty tm
629+elabProvider :: ElabInfo -> SyntaxInfo -> FC -> ProvideWhat -> Name -> PTerm -> PTerm -> Idris ()
630+elabProvider info syn fc what n ty tm
631631 = do i <- getIState
632632 -- Ensure that the experimental extension is enabled
633633 unless (TypeProviders `elem` idris_language_extensions i) $
@@ -647,9 +647,6 @@ elabProvider info syn fc n ty tm
647647 ifail $ "Expected provider type IO (Provider (" ++
648648 show ty' ++ "))" ++ ", got " ++ show et ++ " instead."
649649
650− -- Create the top-level type declaration
651− elabType info syn "" fc [] n ty
652−
653650 -- Execute the type provider and normalise the result
654651 -- use 'run__provider' to convert to a primitive IO action
655652
@@ -658,12 +655,25 @@ elabProvider info syn fc n ty tm
658655 let rhs' = normalise ctxt [] rhs
659656 logLvl 1 $ "Normalised " ++ show n ++ "'s RHS to " ++ show rhs
660657
661− -- Extract the provided term from the type provider
662− tm <- getProvided fc rhs'
663−
664− -- Finally add a top-level definition of the provided term
665− elabClauses info fc [] n [PClause fc n (PApp fc (PRef fc n) []) [] (delab i tm) []]
666− logLvl 1 $ "Elaborated provider " ++ show n ++ " as: " ++ show tm
658+ -- Extract the provided term or postulate from the type provider
659+ provided <- getProvided fc rhs'
660+
661+ case provided of
662+ Provide tm
663+ | what `elem` [ProvTerm, ProvAny] ->
664+ do -- Finally add a top-level definition of the provided term
665+ elabType info syn "" fc [] n ty
666+ elabClauses info fc [] n [PClause fc n (PApp fc (PRef fc n) []) [] (delab i tm) []]
667+ logLvl 1 $ "Elaborated provider " ++ show n ++ " as: " ++ show tm
668+ | otherwise ->
669+ ierror . Msg $ "Attempted to provide a term where a postulate was expected."
670+ Postulate
671+ | what `elem` [ProvPostulate, ProvAny] ->
672+ do -- Add the postulate
673+ elabPostulate info syn "Provided postulate" fc [] n ty
674+ logLvl 1 $ "Elaborated provided postulate " ++ show n
675+ | otherwise ->
676+ ierror . Msg $ "Attempted to provide a postulate where a term was expected."
667677
668678 where isTType :: TT Name -> Bool
669679 isTType (TType _) = True
@@ -2224,10 +2234,10 @@ elabDecl' _ info (PDSL n dsl)
22242234 addIBC (IBCDSL n)
22252235elabDecl' what info (PDirective i)
22262236 | what /= EDefns = i
2227−elabDecl' what info (PProvider syn fc n tp tm)
2237+elabDecl' what info (PProvider syn fc provWhat n tp tm)
22282238 | what /= EDefns
22292239 = do iLOG $ "Elaborating type provider " ++ show n
2230− elabProvider info syn fc n tp tm
2240+ elabProvider info syn fc provWhat n tp tm
22312241elabDecl' what info (PTransform fc safety old new)
22322242 = elabTransform info fc safety old new
22332243elabDecl' _ _ _ = return () -- skipped this time