
Dear list, For some time, I have maintained a small private module centred around the following type of "resource":
newtype Resource cap m = Resource { with :: forall a. (cap -> m a) -> m a }
Interpretation: @Resource cap m@ is a resource, providing a "capability" of type @cap@, which does administration (like opening and closing handles) in the monad @m@. I would like to use a standard module instead of this howe-grown one, so I can publish things that depend on it. Does anyone know a package that provides this? Things I tried: - The type is suspiciously similar to the continuation monad transformer; in fact @Resource cap m@ is isomorphic to @forall t. ContT t m cap@. However, I can't use this latter type directly, because I would like functions on Resources like the instance
instance (Monoid cap) => Monoid (Resource cap m)
, which is not possible without a newtype wrapper. - I tried using the "regions" package, since it has a very similar purpose, but this seems impossible: some resources I could not express in the form required for its class 'Resource' (methods 'open' and 'close'). If something like this is not yet around, I'll upload my version, but I'd like to reuse, if possible. Regards, Arie