All I know is that one works and the other doesn't.
Context:
I have one data structure F
which contains a Data.Map.Map k S
to another data structure S
. My goal was to build a Lens
that given an F
and k
would describe a field in S
.
The difficulty is that the key k
may not be present in the map. That's fine the function can wrap its return in Maybe. However I could not propagate a lens through a Maybe using at
. After reading a lot of Stack Overflow answers, I came across this one.
It turns out that replacing at
with ix
solved my type problems if I also replaced (^.)
with (^?)
.
Question:
It seems like at
and ix
do the same thing, at least with regard to Map
. Both take a key and give a 'Lens' to the value at that key. However, ix
seems to play nice with the function composition operator (.)
. What is the difference between the two?
Off Topic Rant:
I like infix operators as much as the next guy but the Control.Lens package seems to have gone a little overboard. For a new user having some English names and a key somewhere would lower the learning curve. Due to the huge number of wrapper classes used in the Lens library it is particularly difficult to dig through the type signatures if you don't already know what is going on. My code is starting to look like Perl for heaven sake.