[Haskell-beginners] help with types and composition

Sean Bartell wingedtachikoma at gmail.com
Fri Jul 3 00:07:27 EDT 2009


>
> f1 = (zipWith ($)) . (map  (*))
>
> f2 = sum
>

First, f1 would be clearer as zipWith (*).

Second, look at the type of (.):

(.) :: (b -> c) -> (a -> b) -> (a -> c)

Notice that (b -> c) and (a -> b) each take one argument, but f1 takes two
arguments. That's why using (.) with f1 doesn't work.

You can do what you want by uncurrying f1 so it takes only one argument,
which makes it easier to compose. You can then re-curry the result after you
do the composition.

f1 :: [Integer] -> [Integer] -> [Integer]
uncurry f1 :: ([Integer], [Integer]) -> [Integer]
f2 . uncurry f1 :: ([Integer], [Integer]) -> Integer
curry (f2 . uncurry f1) :: [Integer] -> [Integer] -> Integer

I'm sure there are shorter versions that use more than just (.), curry, and
uncurry.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090702/2955a16d/attachment.html


More information about the Beginners mailing list