[Haskell-beginners] help with types and composition
Britt Anderson
britt at uwaterloo.ca
Thu Jul 2 13:54:50 EDT 2009
I would like to write a function that takes two lists of numbers and
returns a number. For simplicity, let's assume an integer, i.e.
myfunc:: [Integer]->[Integer]->Integer
But I can't quite get things right when trying to
define myfunc = ...
and making the arguments implicit.
My difficulty might be seen with the following two functions,
let,
f1 = (zipWith ($)) . (map (*))
f2 = sum
if I set the types such that f1 returns [Integer] and sum accepts
[Integer] it seems that somehow I should be able to compose them in to a
single function that takes two lists and returns the number, but f1 . f2
and numerous variations don't work. I can curry some list l and f1 . (f2
l) works, but is there a way to get f1 and f2 combined into a function
that accepts two lists?
My problem is not really about writing the function but about
composition. I can write the function with arguments or a local lambda
that suits my practical purpose. But the fact that I think I should be
able to compose f1 . f2 somehow reveals a conceptual misunderstanding
that I hope someone will help me clear up.
Thank you,
Britt Anderson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090702/5c952c69/attachment.html
More information about the Beginners
mailing list