
On Friday 02 July 2010 23:15:22, Patrick LeBoutillier wrote:
multRepl = foldl (uncurry . replace)
Actually I've been thinking about this and I can't quite figure out how it works:
I understand the type of replace is
replace :: (Eq a) => [a] -> [a] -> [a] -> [a]
but I can't figure out how the type of (uncurry . replace) becomes
uncurry . replace :: (Eq a) => [a] -> ([a], [a]) -> [a]
?
let's make it foo :: a -> b -> c -> d to not get confused by the fact that replace's arguments and result all have the same type. So, what does uncurry . foo do? Well, (f . g) x = f (g x), so when we apply (uncurry . foo) to an argument x, we get uncurry (foo x) Now, x is the first argument of foo, so x :: a, and (foo x) :: b -> c -> d That means (foo x) has just the type uncurry expects, hence uncurry (foo x) :: (b, c) -> d Now write uncurry (foo x) again as (uncurry . foo) x :: (b, c) -> d and remove x again, so (uncurry . foo) :: a -> (b, c) -> d finally, remember that foo is actually replace and hence all four type variables stand for the same list type (with an Eq constraint).
Patrick