[Haskell-cafe] A use case for *real* existential types

Roman Cheplyaka roma at ro-che.info
Fri May 17 01:12:27 CEST 2013


* oleg at okmij.org <oleg at okmij.org> [2013-05-11 05:26:55-0000]
> I must say though that I'd rather prefer Adres solution because his
> init
> > init :: (forall a. Inotify a -> IO b) -> IO b
> 
> ensures that Inotify does not leak, and so can be disposed of at the
> end. So his init enforces the region discipline and could, after a
> trivial modification to the code, automatically do a clean-up of
> notify descriptors -- something you'd probably want to do.

Well, it is still possible to escape if one wants, using an existential
type:

  data Escape = forall a . Escape (Inotify a) (Watch a)

  main = do
    Escape inotify watch <-
      init $ \inotify -> do
        watch <- addWatch inotify "foo"
        return $ Escape inotify watch

    rmWatch inotify watch

This is because here, unlike in the ST case, the monad itself (IO) is not tagged.

It's probably not easy to do this by accident, but I think "ensures" is
too strong a word here.

Roman



More information about the Haskell-Cafe mailing list