4 ms·
What he was getting at is that you can reuse functions which know nothing about the specific context (like, what container are we mapping over). It's not that y
by jstimpfle 11y ago
What he was getting at is that you can reuse functions which know nothing about the specific context (like, what container are we mapping over). It's not that you couldn't change the type of thing inside.
A little more formally, if you have a functor F you can take some (a -> b) and make it into an (F a -> F b). For example, if F is [] (List), you get ([a] -> [b]).
So [] adds something (a list "context"), but in a sense you don't lose anything (you can still reuse your (a -> b) which knows nothing about the context). That's the wonderful thing about these formal approaches: composability.
(It's sometimes unfortunate that List has this special syntax).
- evincarofautumn 11y agoYou can actually write the list constructor in prefix form if you like: [] a -> [] b
- tome 11y agoAnd if you want to go really crazy type List = [] List a -> List b
- evincarofautumn 11y agotype Function = (->) type On f g a b = f (g a) (g b) {-# LANGUAGE TypeOperators #-} (Function `On` List) a b <_<