module Idris.Providers (providerTy, getProvided) where
import Core.TT
import Core.Evaluate
import Idris.AbsSyntax
import Idris.AbsSyntaxTree
import Idris.Error
import Debug.Trace
providerTy :: FC -> PTerm -> PTerm
providerTy fc tm = PApp fc (PRef fc $ UN "Provider") [PExp 0 False tm ""]
getProvided :: TT Name -> Idris (TT Name)
getProvided tm | (P _ (UN "prim_io_return") _, [tp, result]) <- unApply tm
, (P _ (NS (UN "Error") ["Providers"]) _, [_, err]) <- unApply result =
case err of
Constant (Str msg) -> ierror . ProviderError $ msg
_ -> ifail "Internal error in type provider, non-normalised error"
| (P _ (UN "prim_io_return") _, [tp, result]) <- unApply tm
, (P _ (NS (UN "Provide") ["Providers"]) _, [_, res]) <- unApply result =
return res
| otherwise = ifail $ "Internal type provider error: result was not " ++
"IO (Provider a), or perhaps missing normalisation."