I am trying to do this question from my homework:
Given arbitrary
foo :: [[a]] -> ([a], [a])
, write down one law that the functionfoo
satisfies, involvingmap
on lists and pairs.
Some context: I am a first year undergrad taking a course of functional programming. Whilst the course is rather introductory, the lecturer has mentioned many things out of syllabus, amongst which are the free theorems. So after attempting to read Wadler's paper, I reckoned that concat :: [[a]] -> [a]
with the law map f . concat = concat . map (map f)
looks relevant to my problem, since we must have foo xss = (concat xss, concat' xss)
where concat
and concat'
are any functions of type [[a]] -> [a]
. Then foo
satisfies bimap (map f, map g) . foo = \xss -> ((fst . foo . map (map f)) xss, (snd . foo . map (map g)) xss)
.
Already this 'law' seems too long to be correct, and I am unsure of my logic as well. So I thought of using an online free theorems generator, but I don't get what lift{(,)}
means:
forall t1,t2 in TYPES, g :: t1 -> t2.
forall x :: [[t1]].
(f x, f (map (map g) x)) in lift{(,)}(map g,map g)
lift{(,)}(map g,map g)
= {((x1, x2), (y1, y2)) | (map g x1 = y1) && (map g x2 = y2)}
How should I understand this output? And how should I derive the law for the function foo
properly?