So the above works correctly, but the code looks ugly and doesn't use advanced idioms, such as applicative style.
With applicative approach I don't know how Because every list comprehension is equivalent to do it. I tried the below code, which generates 2 times more elements, because it doesn't know, that if you increment/decrement by 1 on the left sidea lift, you must do it by 2 on the right sideabove code could be rewritten with liftA5
:
[(,)]liftA5 <*>:: ([(+),Applicative g => (a -)]> <*>b [6]-> <*>c [1,-> 2])d <*>-> ([(+),e (-> f)] <*>-> [6]g <*>a [1,-> 2])
g b -> g c -> generates:g [(7,7),(7,8),(7,5),(7,4),(8,7),(8,8),(8,5),(8,4),
d -> g e -> g f
liftA5 f a b c d e = f <$> a <*> b <*> c <*> d <*> e
liftA5 (5,7),\c r f g a -> (5,8)c `f` a, r `g` (5,5invert a),(5,4),) [6] [2] [(4,7+), (4,8-),] [(4,5+), (4,4-)] [1,2]
- HowAre there any way to implementgenerate the generation of suchabove list with applicative stylein a more elegant way?
- How to generalize it to arbitrary possible permutations? (So that my code could parametrized and not fixed to just numbers 1 and 2, or just + and -, etc)
- What intuitions, insights and lessons can I get from this exercise?