I am new not only to Haskell, but to programming in general. I hope that I am posting in the correct forum.
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:
-- snippet from Adapter.InMemory.Auth module as composed on pages 53-64 in the bookThese are the instructions for "Verification in REPL" provided on page 64 of the book:
> :l Adapter.InMemory.AuthCalling the addAuth function is supposed to print the following:
Right "aBNhtG653Bga9kas" -- (or whatever random vCode stringRandomIO generates)However, GHCI instead tells me:
<interactive>:6.9: error:The source code for the book at https://github.com/Apress/practical-webdev-haskell 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 https://hackage.haskell.org, 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.
Beginners mailing list
The issue has nothing to do with STM.
> that would help me understand why the addAuth function thinks the TVar State we pass to it should be a D.Auth
Let's look at the type of `addAuth`:
addAuth :: InMemory r m => D.Auth -> m (Either D.RegistrationError D.VerificationCode)
It takes a single parameter with type `D.Auth`. So you don't have
to pass `s` when you call it.
The `TVar State` value is passed implicitly thanks to the constraint `InMemory r m` (i.e. a value with type `r` can be obtained from `m` Monad thanks to `MonadReader r m` and this value contains a `TVar State` thanks to the `Has (TVar State) r` constraint`).
You can't call `addAuth` directly in GHCI (where `m` would be `IO`), you have to follow the example here: https://github.com/Apress/practical-webdev-haskell/blob/master/03/src/Lib.hs#L30
Or alternatively you can modify `addAuth` for you GHCI test:
On 27/10/2019 19:58, Site Administrator wrote:
Beginners mailing list
|Free forum by Nabble||Edit this page|