error-messages icon indicating copy to clipboard operation
error-messages copied to clipboard

Better MonadFail

Open WinstonHartnett opened this issue 3 years ago • 1 comments

from Haskell GameDev discord

Given a failable ... <- ... pattern on sum type Request with two variants:

unknown

Most users probably don't want to implement a MonadFail instance for monads defined in a library. The following would be more helpful:

    • Failable pattern in non-failable do statement
      `(HaulRequest (resource, requiredAmount) amount)`
      This pattern fails on:
        `ConstructionRequest`
    • Note: the left pattern of `<-` must succeed on 
      all variants unless `MonadFail` is defined
    • Perhaps you intended to handle each variant with `case`:
        `r0 <- get building
         case r0 of
           HaulRequest ...
           ConstructionRequest ...`
    • Perhaps you intended to define a 
      `MonadFail (SystemT World IO)` instance to
      handle failable patterns

WinstonHartnett avatar Jan 14 '22 06:01 WinstonHartnett

https://github.com/ghc-proposals/ghc-proposals/pull/319 was supposed to solve this problem, among other things. Alas. Hopefully I can resurrect it after there is a new -XNoIncomplete to bolster its case.

Ericson2314 avatar Feb 18 '22 07:02 Ericson2314