bbarker / optics-exercises

The Unlicense
1 stars 0 forks source link

Setting values with at #3

Open bbarker opened 4 years ago

bbarker commented 4 years ago

^. is for viewing - it's an alias for flip view where (simplifying) view :: Lens s a -> s -> a. The function ?~ is a modified alias for set over maybe types, where set :: Lens s a -> a -> s -> s. So we write the operator as:

(lens ?~ newValue) old = set lens newValue old

and the common pattern is to use old & lens ?~ newValue

bbarker commented 4 years ago

The above was from parsonmatt - see https://gist.github.com/bbarker/8d52524a2c07de22c52d3acf3fc7b634 for the error on incorrec tuse.