Норм придумал?
type IOObject a = (IO a, a -> IO ())
-- FIXME sane errors
heterObj :: IOObject a -> IOObject a -> IOObject a
heterObj a b = (fst a, snd b)
nulls :: IOObject a
nulls = (throw $ Underflow, const $ return ())
chans :: Chan a -> IOObject a
chans a = (readChan a, writeChan a)
type DataTypeObject a = (a -> ByteString, ByteString -> a)
lazyByteStrings :: DataTypeObject ByteString
lazyByteStrings = (id, id)
showBool True = "true"
showBool False = "false"
readBool s
| s == "1" = True
| s == "true" = True
| s == "0" = False
| s == "false" = False
booleans :: DataTypeObject Bool
booleans = (showBool, readBool)
simpleFile :: forall a m. (Monad m, EmbedIO m)
=> String
-> IOObject a
-> DataTypeObject a
-> NineFile m
simpleFile name (rd, wr) (rdc, wrc) = (boringFile name :: NineFile m) {
read = simpleRead $ liftM rdc $ rd,
write = simpleWrite $ wr . wrc
}