8 import Data.Functor.Identity
11 import Control.Applicative
13 import Control.Monad.State
14 import Control.Monad.Identity
18 :: ErrorT e m a = ErrorT (m (Either e a))
20 runErrorT (ErrorT m) = m
22 instance Functor (ErrorT e m) | Functor m
24 fmap f a = ErrorT $ fmap (fmap f) $ runErrorT a
26 instance Applicative (ErrorT e m) | Functor m & Monad m
28 pure a = ErrorT $ pure $ Right a
29 (<*>) f v = ErrorT $ runErrorT f
31 Left e = pure $ Left e
34 Left e = pure (Left e)
35 Right x = pure $ Right $ k x
37 instance Monad (ErrorT e m) | Monad m
39 bind m k = ErrorT $ runErrorT m
41 Left l = pure $ Left l
42 Right r = runErrorT (k r)
44 :: IOT m a = IOT (*World -> *(m a, *World))
48 instance Functor (IOT m) | Functor m
50 fmap f a = IOT \w->appFst (fmap f) $ runIOT a w
51 //instance Applicative (IOT m) | Applicative m
53 // pure a = IOT $ tuple $ pure a
54 // (<*>) f v = IOT \w->
56 // (Left e, w) = (Left e, w)
57 // (Right ff, w) = case runIOT v w of
58 // (Left e, w) = (Left e, w)
59 // (Right fv, w) = (Right (ff fv), w)
62 //liftIOT :: (*World -> *(MaybeError e a, *World)) -> ErrorT e (StateT *World Identity) String
63 //liftIOT f = ErrorT $ StateT \w->case f w of
64 // (Ok a, w`) = pure (pure a, w`)
66 liftIO :: (*World -> *(a, *World)) -> State *World a
69 Start = 42//liftIOT (readFile "/opt/clean/etc/IDEEnvs")