4 ms·
import Debug.Trace myPureThing :: Bool -> Int myPureThing b = if b then traceShow "yay True" 42 else trac
by unhammer 7y ago
import Debug.Trace
myPureThing :: Bool -> Int
myPureThing b = if b
then traceShow "yay True" 42
else traceShow "oh noes False" 13
…
λ> myPureThing True
"yay True"
42
λ> myPureThing False
"oh noes False"
13
I don't know if they're good for others, but I read Real World Haskell[1] and Learn You a Haskell[2]. There's also Graham Hutton's book which people like and which is free to read this month or something[3].
[1] http://book.realworldhaskell.org/ http://book.realworldhaskell.org/ – see also the in-progress updated version at https://github.com/tssm/up-to-date-real-world-haskell https://github.com/tssm/up-to-date-real-world-haskell
[2] http://learnyouahaskell.com/ http://learnyouahaskell.com/
[3] https://www.cambridge.org/core/books/programming-in-haskell/8FED82E807EF12D390DE0D16FDE217E4 https://www.cambridge.org/core/books/programming-in-haskell/...
- awinter-py 7y agoack sorry, I meant how to add a debug statement to an existing pure function while still having it return the original value EDIT per comment below, I totally misread this! yes exactly, traceShow ftw You saved me another N hours
- tome 7y agoIsn't that exactly what unhammer is demonstrating?
- awinter-py 7y agooops yes
- hopia 7y agoIn principle, you wouldn't do any logging, even debug logging, in a pure function. It always returns the same output for the same input anyway. You'd just check its output.