<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <font face="Liberation Serif">Hello,<br>
      <br>
      I am new not only to Haskell, but to programming in general. I
      hope that I am posting in the correct forum.<br>
      <br>
      I am working through "Practical Web Development With Haskell" by
      Ecky Putrady (2018), New York: Apress, and I am having some
      difficulty understanding the STM portion of Chapter three. More
      specifically, I cannot get the following code snippet to return
      the expected result in the REPL:<br>
    </font>
    <blockquote><font face="Liberation Serif">-- snippet from
        Adapter.InMemory.Auth module as composed on pages 53-64 in the
        book<br>
        import ClassyPrelude<br>
        import qualified Domain.Auth as D -- as composed on pages 35-52
        in the book<br>
        import Conrol.Monad.Except<br>
        import Text.StringRandom<br>
        import Data.Has<br>
        -- ...<br>
        data State = State<br>
          { stateAuths :: [(D.UserId, D.Auth)]<br>
        -- ...<br>
        initialState :: State<br>
        initialState = State<br>
          { stateAuths = []<br>
        -- ...<br>
        type InMemory r m = (Has (TVar State) r, MonadReader r m,
        MonadIO m)<br>
        <br>
        addAuth :: InMemory r m<br>
                       => D.Auth -> m (Either D.RegistrationError
        D.VerificationCode)<br>
        addAuth auth = do<br>
          tvar <- asks getter<br>
        -- ... rest of function<br>
      </font></blockquote>
    <font face="Liberation Serif">These are the instructions for
      "Verification in REPL" provided on page 64 of the book:<br>
    </font>
    <blockquote><font face="Liberation Serif">> :l
        Adapter.InMemory.Auth<br>
        > let email = D.mkEmail <a class="moz-txt-link-rfc2396E" href="mailto:ecky@test.com">"ecky@test.com"</a><br>
        > let passw = D.mkPassword "1234ABCDefgh"<br>
        > let auth = either undefined id $ D.Auth <$> email
        <*> passw<br>
        > s <- newTVarIO initialState<br>
        > addAuth s auth<br>
      </font></blockquote>
    <font face="Liberation Serif">Calling the addAuth function is
      supposed to print the following:<br>
    </font>
    <blockquote><font face="Liberation Serif">Right "aBNhtG653Bga9kas"
        -- (or whatever random vCode stringRandomIO generates)<br>
      </font></blockquote>
    <font face="Liberation Serif">However, GHCI instead tells me:<br>
    </font>
    <blockquote><font face="Liberation Serif"><interactive>:6.9:
        error:<br>
               * Couldn't match expected type 'D.Auth'<br>
                                       with actual type 'TVar State'<br>
               * In the first argument of 'addAuth', namely 's'<br>
                  In the expression: addAuth s auth<br>
        -- ...<br>
      </font></blockquote>
    <font face="Liberation Serif">The source code for the book at
      <a class="moz-txt-link-freetext" href="https://github.com/Apress/practical-webdev-haskell">https://github.com/Apress/practical-webdev-haskell</a> was created
      with stack resolver lts-9.11, while I am using resolver lts-14.11.
      I am doing this intentionally, because debugging the compilation
      errors helps guide me to become more familiar with the
      documentation in the packages being implemented, as well as
      helping me to understand general Haskell concepts little by
      little. I have tried looking through the changelogs for the stm
      and classy-prelude packages on <a class="moz-txt-link-freetext" href="https://hackage.haskell.org">https://hackage.haskell.org</a>, for
      any clues which would be intelligible to me (an extremely
      restrictive constraint, admittedly), that would help me understand
      why the addAuth function thinks the TVar State we pass to it
      should be a D.Auth, and why this presumably would not have been
      the case had I built the project with the lts-9.11 resolver, but I
      have not been able to understand it thus far. <br>
      <br>
      <br>
    </font>
  </body>
</html>