2
votes

I'm trying to make the chat example from the Yesod book working in the scaffolding site.

I think I've corrected almost all I had to correct, but all of that is completely new to me (it's my first "real" Haskell project) and I'm not very confident in all my modifications; moreover, I'm really stuck at the point 7. Could you comment all the following points if necessary, and helping me for the 7. (in bold some questions/remarks)?

  1. Copy/paste the Chat.hs and Chat/Data.hs in the root of my site,
  2. add import Chat as Import and import Chat.Data as Import to Import.NoFoundation,
  3. add import of IO, Bool, return, Maybe(Nothing), ($) in Data.hs, since the extension NoImplicitPrelude is on Seems very clumsy... Do we have to import all the standard operators on each new file?
  4. in Fundation.hs, add getChat in the App record (after appHttpManager and appLogger)
  5. in Fundation.hs, add YesodChat instance for App: I had to modify the getUserName on the Just uid case (in the original example of Chat, it was just Just uid -> return uid):

            Just uid -> do
            muser <- runDB  $ get uid
            case muser of
                Nothing -> error "uid not in the DB"
                Just user ->  return $ userIdent user
    

    This seems very long and nested... Can we do better?

  6. In Fundation.hs, add chatWidget ChatR after the line pc <- widgetToPageContent $ do in the defaultLayout definition.
  7. Now, I have the following warning :

    Application.hs:60:36: Warning:
    
    Fields of ‘App’ not initialised: getChat
    In the expression: App {..}
    

    I think I have to write something like getChat <- newChan >>=Chat after the appLogger <- newStdoutLoggerSet defaultBufSize >>= makeYesodLogger and appStatic <- ... in the makeFundation definition, but the type doesn't match. I'm a totally lost here, I don't really understand how this function makeFundation works.

1

1 Answers

2
votes

You actually got almost the entire way there. I think you just need to change the line to:

getChat <- fmap Chat newChan

Alternatively, if you're not familiar with he fmap function yet, you can use do notation and get:

chan <- newChan
let getChat = Chat chan