[Haskell-cafe] Track Exceptions

Roman Cheplyaka roma at ro-che.info
Thu Mar 13 16:54:59 UTC 2014


* Ruud Koot <r.koot at uu.nl> [2014-03-13 17:45:12+0100]
> 1) Consider the higher-order function 'map'. With tracked exceptions
> you would probably want to give it a type such as:
> 
>     map :: forall a b e. (a -> b throws e) -> [a] -> [b] throws e
> 
> I.e., you need some kind of exception polymorphism, or severely
> restrict the kind of functions you would be allowed to pass to map
> (basically those that are guaranteed to not raise any exceptions).

Simply instantiating b with b `Throws` e gives

  map :: (a -> b `Throws` e) -> [a] -> [b `Throws` e]

Which is actually a more useful type than the one you proposed, because it shows
that map itself doesn't throw exceptions (so that e.g. computing length is
safe).

Assuming "Throws e" is a monad, you could use mapM instead of map to get the
behavior you want.

In fact, Throws will probably need to be an indexed monad.

Roman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140313/589045f0/attachment.sig>


More information about the Haskell-Cafe mailing list