You can write the Getter
using to
(you could give -.-
lower precedence to get rid of the parentheses):
workLogDurationRO = to $ \wl -> (wl^.workLogEndTime) -.- (wl^.workLogStartTime)
But as the lens wiki says, you're probably better off with a normal function that computes the time difference, which you can then use with to
when you need it as a lens.
You can build the Lens'
from a getter (same as above) and a setter:
workLogDurationRW = lens get set
where
get :: WorkLog -> TimeDifference
get wl = (wl^.workLogEndTime) -.- (wl^.workLogStartTime)
set :: WorkLog -> TimeDifference -> WorkLog
set wl timeDiff = wl & workLogEndTime .~ (wl^.workLogStartTime) +.+ timeDiff
where
TimeStamp a +.+ TimeDifference b = TimeStamp (a + b)