Skip to content

No instance for (Control.Monad.Fail.MonadFail App) on P66 #4

Description

@paulspencerwilliams

When trying to compile the last source code changes for chapter 3, I received the following error:

Lib.hs:46:3: error:
    • No instance for (Control.Monad.Fail.MonadFail App)
        arising from a do statement
        with the failable pattern ‘Just registeredEmail’
    • In a stmt of a 'do' block: Just registeredEmail <- getUser uId
      In the expression:
        do let email = either undefined id $ mkEmail "ecky@test.com"
               passw = either undefined id $ mkPassword "1234ABCDefgh"
               ....
           register auth
           Just vCode <- M.getNotificationsForEmail email
           verifyEmail vCode
           ....
      In an equation for ‘action’:
          action
            = do let email = ...
                     ....
                 register auth
                 Just vCode <- M.getNotificationsForEmail email
                 ....
   |
46 |   Just  registeredEmail <- getUser uId

I found a resolution on Reddit, and I've copied it to ensure it survives.

Into Lib.hs I imported

import           Control.Monad                  ( MonadFail )

and added MonadFail to App's deriving list:

newtype App a = App
  { unApp :: ReaderT State IO a
  } deriving (Applicative, Functor, Monad, MonadReader State, MonadIO, MonadFail)

which allowed me to build, and run somefunc into the repl

ghci> someFunc 
("1Bk40ZG6XGJ1bsqWV",1,Email {emailRaw = "ecky@test.com"})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions