Because runWriter
is a record field accessor on Writer
. It's actually almost equivalent to
runWriter (Writer x) = x
Haskell just has records to give
- More convient syntax since this sort of accessor code is quite common
- The ability for functional updates
- A few other extensions
eg
someWriter{runWriter = (new, values)} -- Returns a new Writer.
If it helps, think of it as something like a "functional getter" in the roughest sense. This might not seem terribly important with 1 field, you can always pattern match, but when you have 5 fields, records + functional updates are super helpful. See LYAH for a more in depth explanation.