Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
pp:functors [2021/04/19 11:19] lfa [1. Example: the Maybe functor] |
pp:functors [2021/04/21 15:51] (current) alexandru.rait Changed 6 to 7 in title |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== 6. Functors, Foldables ====== | + | ====== 7. Functors, Foldables ====== |
| Functors are data types over which we can ''map'' a function (that is, apply a function on each element while keeping the overall structure). You've already encountered a Functor, namely haskell lists. For historical reasons, ''map'' only works on lists (''map :: (a -%%>%% b) -%%>%% [a] -%%>%% [b]''), but there exists a more general function ''fmap'' (''fmap :: (Functor f) =%%>%% (a -%%>%% b) -%%>%% f a -%%>%% f b''). | Functors are data types over which we can ''map'' a function (that is, apply a function on each element while keeping the overall structure). You've already encountered a Functor, namely haskell lists. For historical reasons, ''map'' only works on lists (''map :: (a -%%>%% b) -%%>%% [a] -%%>%% [b]''), but there exists a more general function ''fmap'' (''fmap :: (Functor f) =%%>%% (a -%%>%% b) -%%>%% f a -%%>%% f b''). | ||