I would like to set an item at position x between two lists, as if they were the same list.
For example:
data Foo = Foo {
list1 :: [Char],
list2 :: [Char]}
foo = Foo ['a', 'b', 'c'] ['d', 'e', 'f']
setItem :: Int -> Char -> Foo -> Foo
setItem i c f = ???
For instance, setting element at position 5 would yield:
setItem 5 'X' foo
==> Foo ['a', 'b', 'c'] ['d', 'X', 'f']
I thought I could use optics/lens for this. Something like (using Optics and Labels):
setItem :: Int -> Char -> Foo -> Foo
setItem i c f = set ((#list1 <> #list2) % at i) c f
But this doesn't work:
No instance for (Semigroup (Optic k1 NoIx s0 t0 v0 v0))