1{-# LANGUAGE PatternGuards, DeriveFunctor #-}
2module Idris.Providers (providerTy, getProvided, Provided(..)) where
5import Idris.Core.Evaluate
7import Idris.AbsSyntaxTree
12-- | Wrap a type provider in the type of type providers
13providerTy :: FC -> PTerm -> PTerm
15 = PApp fc (PRef fc $ sUN "Provider") [PExp 0 [] (sMN 0 "pvarg") tm]
17ioret = sUN "prim_io_return"
18ermod = sNS (sUN "Error") ["Providers"]
19prmod = sNS (sUN "Provide") ["Providers"]
20posmod = sNS (sUN "Postulate") ["Providers"]
22data Provided a = Provide a
24 deriving (Show, Eq, Functor)
26-- | Handle an error, if the type provider returned an error. Otherwise return the provided term.
27getProvided :: FC -> TT Name -> Idris (Provided (TT Name))
28getProvided fc tm | (P _ pioret _, [tp, result]) <- unApply tm
29 , (P _ nm _, [_, err]) <- unApply result
30 , pioret == ioret && nm == ermod
32 Constant (Str msg) -> ierror . At fc . ProviderError $ msg
33 _ -> ifail "Internal error in type provider, non-normalised error"
34 | (P _ pioret _, [tp, result]) <- unApply tm
35 , (P _ nm _, [_, res]) <- unApply result
36 , pioret == ioret && nm == prmod
37 = return . Provide $ res
38 | (P _ pioret _, [tp, result]) <- unApply tm
39 , (P _ nm _, [_]) <- unApply result
40 , pioret == ioret && nm == posmod
42 | otherwise = ifail $ "Internal type provider error: result was not " ++
43 "IO (Provider a), or perhaps missing normalisation."
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list