module test import StdEnv import Data.Func import Data.Either import Data.Functor import Data.Functor.Identity import Data.Tuple import Data.Error import Control.Applicative import Control.Monad import Control.Monad.State import Control.Monad.Identity import System.File :: ErrorT e m a = ErrorT (m (Either e a)) runErrorT (ErrorT m) = m instance Functor (ErrorT e m) | Functor m where fmap f a = ErrorT $ fmap (fmap f) $ runErrorT a instance Applicative (ErrorT e m) | Functor m & Monad m where pure a = ErrorT $ pure $ Right a (<*>) f v = ErrorT $ runErrorT f >>= \mf->case mf of Left e = pure $ Left e Right k = runErrorT v >>= \mv->case mv of Left e = pure (Left e) Right x = pure $ Right $ k x instance Monad (ErrorT e m) | Monad m where bind m k = ErrorT $ runErrorT m >>= \a->case a of Left l = pure $ Left l Right r = runErrorT (k r) :: IOT m a = IOT (*World -> *(m a, *World)) runIOT (IOT f) = f instance Functor (IOT m) | Functor m where fmap f a = IOT \w->appFst (fmap f) $ runIOT a w //instance Applicative (IOT m) | Applicative m //where // pure a = IOT $ tuple $ pure a // (<*>) f v = IOT \w-> // case runIOT f w of // (Left e, w) = (Left e, w) // (Right ff, w) = case runIOT v w of // (Left e, w) = (Left e, w) // (Right fv, w) = (Right (ff fv), w) //liftIOT :: (*World -> *(MaybeError e a, *World)) -> ErrorT e (StateT *World Identity) String //liftIOT f = ErrorT $ StateT \w->case f w of // (Ok a, w`) = pure (pure a, w`) liftIO :: (*World -> *(a, *World)) -> State *World a liftIO f = state f Start = 42//liftIOT (readFile "/opt/clean/etc/IDEEnvs")