Question

I thought I had Yesod types well in hand for my simple needs. Hah! Here are two functions that compile right now, but do not do exactly what I would like at the moment, and I'm not sure how to proceed.

    addNote' selectedProduct = do  
      _ <- runDB $ insert <=< liftIOHandler $ addNote selectedProduct
      return ()


--    addNote :: SelectedProduct -> IO (NotesGeneric SqlPersist)
addNote (MKsp tid firmware version _ requester (Textarea note)) = do
--   currentTime <- getCurrentTime
   return $ Notes tid requester firmware version note undefined

I have the type signature of addNote commented out for a reason, if I uncomment it, or the call to getCurrentTime, I get the error I will display below.

I don't know what the type of addNote' is. GHC says it is the following:

    Warning: Top-level binding with no type signature:
               addNote' :: forall master (monad :: * -> *) sub sub1 master1.
                           (YesodPersistBackend master
                              ~
                            Control.Monad.Trans.Reader.ReaderT (HandlerData sub1 master1),
                            YesodPersist master,
                            PersistBackend
                              (Control.Monad.Trans.Reader.ReaderT (HandlerData sub1 master1))
                              (GGHandler sub master IO),
                            Control.Monad.IO.Class.MonadIO monad) =>
                           SelectedProduct
                           -> Control.Monad.Trans.Reader.ReaderT
                                (HandlerData sub master) monad ()

Also, GHC says the type of addNote is this:

           addNote :: forall (m :: * -> *).
                      Monad m =>
                      SelectedProduct -> m (NotesGeneric SqlPersist)

Here is the error I get if I uncomment out the getUTCTime line, or the type signature for addNote.

Couldn't match expected type `Control.Monad.Trans.Reader.ReaderT
                                (HandlerData sub0 master0) IO b0'
            with actual type `IO (NotesGeneric SqlPersist)'
Expected type: GGHandler sub0 master0 IO b0
  Actual type: IO (NotesGeneric SqlPersist)
In the return type of a call of `addNote'
In the second argument of `($)', namely `addNote selectedProduct'

How do I go about getting the types to match?

Was it helpful?

Solution

Just replace liftIOHandler with liftIO. liftIOHandler is a dirty hack that's only necessary in very rare circumstances, and fortunately is completely gone starting with Yesod 0.10.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top