Skip to content

Commit 9a512ca

Browse files
committed
further text adjustment
1 parent fc9e79d commit 9a512ca

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

source_md/for-a-few-monads-more.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ applyLog :: (Monoid m) => (a,m) -> (a -> (b,m)) -> (b,m)
153153
applyLog (x,log) f = let (y,newLog) = f x in (y,log <> newLog)
154154
```
155155

156+
Actually, this code works for any semigroup, not just monoids.
157+
But I'll just ignore that, as we'll be using an identity value shortly anyway.
158+
156159
Because the accompanying value can now be any monoid value, we no longer have to think of the tuple as a value and a log, but now we can think of it as a value with an accompanying monoid value.
157160
For instance, we can have a tuple that has an item name and an item price as the monoid value.
158161
We just use the `Sum` newtype to make sure that the prices get added as we operate with the items.

0 commit comments

Comments
 (0)