@@ -1,5 +1,5 @@
1−{-# LANGUAGE PatternGuards #-}
2−module Idris.Providers (providerTy, getProvided) where
1+{-# LANGUAGE PatternGuards, DeriveFunctor #-}
2+module Idris.Providers (providerTy, getProvided, Provided(..)) where
33
44import Idris.Core.TT
55import Idris.Core.Evaluate
@@ -16,9 +16,14 @@ providerTy fc tm = PApp fc (PRef fc $ sUN "Provider") [PExp 0 [] tm ""]
1616ioret = sUN "prim_io_return"
1717ermod = sNS (sUN "Error") ["Providers"]
1818prmod = sNS (sUN "Provide") ["Providers"]
19+posmod = sNS (sUN "Postulate") ["Providers"]
20+
21+data Provided a = Provide a
22+ | Postulate
23+ deriving (Show, Eq, Functor)
1924
2025-- | Handle an error, if the type provider returned an error. Otherwise return the provided term.
21−getProvided :: FC -> TT Name -> Idris (TT Name)
26+getProvided :: FC -> TT Name -> Idris (Provided (TT Name))
2227getProvided fc tm | (P _ pioret _, [tp, result]) <- unApply tm
2328 , (P _ nm _, [_, err]) <- unApply result
2429 , pioret == ioret && nm == ermod
@@ -28,7 +33,11 @@ getProvided fc tm | (P _ pioret _, [tp, result]) <- unApply tm
2833 | (P _ pioret _, [tp, result]) <- unApply tm
2934 , (P _ nm _, [_, res]) <- unApply result
3035 , pioret == ioret && nm == prmod
31− = return res
36+ = return . Provide $ res
37+ | (P _ pioret _, [tp, result]) <- unApply tm
38+ , (P _ nm _, [_]) <- unApply result
39+ , pioret == ioret && nm == posmod
40+ = return Postulate
3241 | otherwise = ifail $ "Internal type provider error: result was not " ++
3342 "IO (Provider a), or perhaps missing normalisation."
3443