@@ -18,12 +18,12 @@
1818 programs with implicit syntax into fully explicit terms.
1919-}
2020
21−module Idris.Core.TT(module Idris.Core.TT, module Idris.Core.TC) where
22−
23−import Idris.Core.TC
21+module Idris.Core.TT where
2422
23+import Control.Applicative (Applicative (..), Alternative)
24+import qualified Control.Applicative as A (Alternative (..))
2525import Control.Monad.State.Strict
26−import Control.Monad.Trans.Error (Error(..))
26+import Control.Monad.Trans.Except (Except (..))
2727import Debug.Trace
2828import qualified Data.Map.Strict as Map
2929import Data.Char
@@ -162,6 +162,36 @@ data Err' t
162162
163163type Err = Err' Term
164164
165+data TC a = OK !a
166+ | Error Err
167+ deriving (Eq, Functor)
168+
169+bindTC :: TC a -> (a -> TC b) -> TC b
170+bindTC x k = case x of
171+ OK v -> k v
172+ Error e -> Error e
173+{-# INLINE bindTC #-}
174+
175+instance Monad TC where
176+ return x = OK x
177+ x >>= k = bindTC x k
178+ fail e = Error (InternalMsg e)
179+
180+instance MonadPlus TC where
181+ mzero = fail "Unknown error"
182+ (OK x) `mplus` _ = OK x
183+ _ `mplus` (OK y) = OK y
184+ err `mplus` _ = err
185+
186+
187+instance Applicative TC where
188+ pure = return
189+ (<*>) = ap
190+
191+instance Alternative TC where
192+ empty = mzero
193+ (<|>) = mplus
194+
165195{-!
166196deriving instance NFData Err
167197!-}
@@ -234,11 +264,6 @@ instance Pretty Err OutputAnnotation where
234264 pretty err@(LoadingFailed _ _) = text (show err)
235265 pretty _ = text "Error"
236266
237−instance Error Err where
238− strMsg = InternalMsg
239−
240−type TC = TC' Err
241−
242267instance (Pretty a OutputAnnotation) => Pretty (TC a) OutputAnnotation where
243268 pretty (OK ok) = pretty ok
244269 pretty (Error err) =