Closed Sose closed 3 years ago
Hi, thanks for bringing that up!
The issue here is that the arguments to compose
are indeed "the wrong way around" compared to mathematics. This can be seen from the types. Compare
compose :: (Eq a, Eq b) => [(a,b)] -> [(b,c)] -> [(a,c)]
(.) :: (b -> c) -> (a -> b) -> a -> c
I'll try to clarify the exercise text a bit. Also, it looks like the tests pretty much only test permute
with compose
, so I guess your permute
is wrong. I'll add a simpler test for just permute
that might help you.
Check the note I added to the exercise description and the new test for permute
. Perhaps they'll help you!
(You can get the new exercise template and test using git pull
)
Ah, now I see how my solution is wrong. Thanks for clarifying and adding the new test! I guess this can be closed
Hey, I'm not an expert on this and it is possible I'm wrong but I think there is an issue with the tests in Chapter 9a. My
compose
function seems to pass any tests related to it and mypermute
function fails only when checked together withcompose
(although there aren't many automated tests but I tested with the examples given in comments).According to http://www.efgh.com/math/algebra/permutations.htm the composition of two permutations is the same as the composition of two functions.
(f . g)(x) = f(g(x))
(g is applied first and then f)Composing permutations should follow the same rule?
permute (p `compose` q) xs = permute p (permute q xs)
(apply q first, then p)However, the explanation in Set9a.hs and the tests in Set9aTest.hs seem to test that
permute (p `compose` q) xs = permute q (permute p xs)
I tried to translate the composition example from the website to Haskell like this