input-output-hk / io-sim

Haskell's IO simulator which closely follows core packages (base, async, stm).
https://hackage.haskell.org/package/io-sim
Apache License 2.0
37 stars 15 forks source link

Bring the order of type arguments for `try` in line with `Control.Exception.try` #191

Open jorisdral opened 5 hours ago

jorisdral commented 5 hours ago

Control.Exception.Try and Control.Monad.Class.MonadThrow.try have a different order of type arguments. I think we should follow what Control.Exception.Try does, because it makes it easier to specify the exception type we want to catch, e.g. try @SomeException. Control.Monad.Class.MonadThrow.try wants you to specify the monad first, so you end up having to write try @m @SomeException instead.

https://github.com/input-output-hk/io-sim/blob/13fa0cf4b1287d4a03f65c8e090a1a5bcd948098/io-classes/src/Control/Monad/Class/MonadThrow.hs#L90

There might be other functions in MonadThrow and co that could benefit from explicitly ordering type arguments, but changing try should be a good starting point.

jorisdral commented 5 hours ago

Is it even possible to do this if m is mentioned in the MonadThrow class head? Do we have to define helper functions that reorder the type arguments?

bolt12 commented 5 hours ago

That's a good question! A helper function would do it. I am also not sure if moving the constraint from the class head to the function type would do anything.