4 ms·
Okay, now that I have a moment, here’s how to do it with proper encapsulation. The previous example let you perform arbitrary IO with “liftIO”, which is exactly
by evincarofautumn 14y ago
Okay, now that I have a moment, here’s how to do it with proper encapsulation. The previous example let you perform arbitrary IO with “liftIO”, which is exactly not what you want.
class MonadTT m where
ttGetLine :: m String
ttPutStrLn :: String -> m ()
instance MonadTT IO where
ttGetLine = getLine
ttPutStrLn = putStrLn
class MonadFS m where
fsReadFile :: FilePath -> m String
instance MonadFS IO where
fsReadFile = readFile
cat :: (MonadTT m, MonadFS m) => FilePath -> m ()
- ibotty 14y agoyou are of course right, that that would work. i was wondering more whether it is possible to structure the io monad (using algebras as in data types a la carte) or as you did here while _preserving backwards compatability_. right now io is very broad and can be pretty much everything. it should be more fine-grained. (i still have to look into safe haskell and it's rio, but my superficial look says, it's something different.)