-
Notifications
You must be signed in to change notification settings - Fork 56
Closed
Description
I haven't used this extension myself previously, so my understanding may not be perfect. Consider this script:
#!/usr/bin/env stack
-- stack --resolver nightly-2018-04-15 script
{-# LANGUAGE NoImplicitPrelude #-}
-- {-# LANGUAGE MonadFailDesugaring #-}
{-# OPTIONS_GHC -Wall -Werror #-}
import RIO
main :: IO ()
main = runRIO () $ do
Just x <- return Nothing
return xAs is, it will crash at runtime with:
Main.hs: user error (Pattern match failure in do expression at /Users/michael/Desktop/Main.hs:10:3-8)
Note that even with -Wall -Werror turned on, the compiler does nothing to prevent us from the partial pattern match Just x <- return Nothing. By contrast, if we uncomment the {-# LANGUAGE MonadFailDesugaring #-} line, we get a compiler time error due to a missing MonadFail instance instead:
/Users/michael/Desktop/Main.hs:10:3: error:
• No instance for (Control.Monad.Fail.MonadFail (RIO ()))
arising from a do statement
with the failable pattern ‘Just x’
• In a stmt of a 'do' block: Just x <- return Nothing
In the second argument of ‘($)’, namely
‘do Just x <- return Nothing
return x’
In the expression:
runRIO ()
$ do Just x <- return Nothing
return x
|
10 | Just x <- return Nothing
It seems preferable to me to totally block partial pattern matches via this language extension and lack of MonadFail instance for RIO.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels