Timeline for Removing OO style coding from Haskell
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 9, 2020 at 16:52 | comment | added | cole |
Yes, it is getting the state that was modified by guess newGuess . The docs probably aren’t going to help much here if you’re confused. One way to see that it works is to mentally inline the code in guess . But what I recommend doing is writing out the monad instance for newtype State a s = s -> (a,s) . It’s not too bad if you follow the types. It might help to learn/remember how currying works in Haskell and that a -> (b -> c) = a -> b -> c . Once you know how >>= and return are implemented, you can desugar the do notation and see why it works.
|
|
Jul 9, 2020 at 16:44 | history | edited | cole | CC BY-SA 4.0 |
added 9 characters in body; deleted 6 characters in body
|
Jul 9, 2020 at 13:14 | vote | accept | gust | ||
Jul 9, 2020 at 13:13 | comment | added | gust |
That being said, in the gameLoop function, you just use newHangman <- get -- is it getting the state from val <- guess newGuess even though nothing is explicitly put ? I couldn't figure this out by looking at simply the docs...
|
|
Jul 9, 2020 at 13:11 | comment | added | gust | Thank you, this is amazing! So much cleaner code to read! | |
Jul 8, 2020 at 4:39 | history | edited | cole | CC BY-SA 4.0 |
explain why StateT isn't desirable
|
Jul 8, 2020 at 4:28 | history | answered | cole | CC BY-SA 4.0 |