1-----------------------------------------------------------------------------
3-- Module : PureScript.TypeChecker.Monad
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15{-# LANGUAGE GeneralizedNewtypeDeriving, FlexibleInstances #-}
17module PureScript.TypeChecker.Monad where
19import PureScript.Types
20import PureScript.Kinds
22import Control.Applicative
23import Control.Monad.State
24import Control.Monad.Error
26import Control.Arrow ((***))
28import qualified Data.Map as M
30data Environment = Environment
31 { names :: M.Map String Type
32 , types :: M.Map String Kind
35emptyEnvironment :: Environment
36emptyEnvironment = Environment M.empty M.empty
38newtype Check a = Check { unCheck :: StateT (Environment, Int) (Either String) a } deriving (Functor, Monad, Applicative, MonadPlus, MonadState (Environment, Int), MonadError String)
40getEnv :: Check Environment
43putEnv :: Environment -> Check ()
44putEnv env = fmap (const env *** id) get >>= put
52check :: Check a -> Either String (a, Environment)
53check = fmap (id *** fst) . flip runStateT (emptyEnvironment, 0) . unCheck
55guardWith :: (MonadError e m) => e -> Bool -> m ()
56guardWith _ True = return ()
57guardWith e False = throwError e
59rethrow :: (MonadError e m) => (e -> e) -> m a -> m a
60rethrow f = flip catchError $ \e -> throwError (f e)
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