[Q] A typing problem

Hi ! I'm trying to write a function that combines folding and mapping. This function would take two arguments (a folding function and a mapping function), and would return a function of one argument (a list of 'a''s) returning a 'a'. The idea is to write something like sumsquare = foldmap (+) square Here's what I write: foldmap :: (c -> c -> c) -> (c -> c) -> (c -> c -> c) foldmap f m = foldr1 f (map m) But this gives a typing error: ERROR "src/ssq4.hs":2 - Type error in application *** Expression : foldr1 f (map m) *** Term : map m *** Type : [b] -> [b] *** Does not match : [a] What can I do to get what I want ? Thanks. -- Didier Verna, didier@lrde.epita.fr, http://www.lrde.epita.fr/~didier EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (1) 44 08 01 85 94276 Le Kremlin-BicĂȘtre, France Fax.+33 (1) 53 14 59 22 didier@xemacs.org

On Wed, 13 Apr 2005, Didier Verna wrote:
I'm trying to write a function that combines folding and mapping. This function would take two arguments (a folding function and a mapping function), and would return a function of one argument (a list of 'a''s) returning a 'a'.
The idea is to write something like sumsquare = foldmap (+) square
Here's what I write:
foldmap :: (c -> c -> c) -> (c -> c) -> (c -> c -> c) foldmap f m = foldr1 f (map m)
Do you mean foldmap :: (b -> b -> b) -> (a -> b) -> [a] -> b foldmap f m = foldr1 f . map m ?

Henning Thielemann
Do you mean
foldmap :: (b -> b -> b) -> (a -> b) -> [a] -> b foldmap f m = foldr1 f . map m
But of course ! Thanks :-) -- Didier Verna, didier@lrde.epita.fr, http://www.lrde.epita.fr/~didier EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (1) 44 08 01 85 94276 Le Kremlin-BicĂȘtre, France Fax.+33 (1) 53 14 59 22 didier@xemacs.org

I'm trying to write a function that combines folding and mapping
a map is a fold:) idList = foldr (:) [] map f = foldr ((:) . f) []
foldmap :: (b -> b -> b) -> (a -> b) -> [a] -> b foldmap f m = foldr1 f . map m
alternatively, and dealing with empty lists as well foldmap op n f = foldr (op . f) n cheers, claus
participants (3)
-
Claus Reinke
-
Didier Verna
-
Henning Thielemann