1{-# LANGUAGE PatternGuards, DeriveFunctor #-}
2module Idris.Providers (providerTy, getProvided, Provided(..)) where
5import Idris.Core.Evaluate
7import Idris.AbsSyntaxTree
10-- | Wrap a type provider in the type of type providers
11providerTy :: FC -> PTerm -> PTerm
13 = PApp fc (PRef fc $ sNS (sUN "Provider" ) ["Providers", "Prelude"]) [PExp 0 [] (sMN 0 "pvarg") tm]
16ioret = sUN "prim_io_return"
19ermod = sNS (sUN "Error") ["Providers", "Prelude"]
22prmod = sNS (sUN "Provide") ["Providers", "Prelude"]
24data Provided a = Provide a
25 deriving (Show, Eq, Functor)
27-- | Handle an error, if the type provider returned an error. Otherwise return the provided term.
28getProvided :: FC -> TT Name -> Idris (Provided (TT Name))
29getProvided fc tm | (P _ pioret _, [tp, result]) <- unApply tm
30 , (P _ nm _, [_, err]) <- unApply result
31 , pioret == ioret && nm == ermod
33 Constant (Str msg) -> ierror . At fc . ProviderError $ msg
34 _ -> ifail "Internal error in type provider, non-normalised error"
35 | (P _ pioret _, [tp, result]) <- unApply tm
36 , (P _ nm _, [_, res]) <- unApply result
37 , pioret == ioret && nm == prmod
38 = return . Provide $ res
39 | otherwise = ifail $ "Internal type provider error: result was not " ++
40 "IO (Provider a), or perhaps missing normalisation." ++
41 "Term: " ++ take 1000 (show tm)
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