2 ms·
In my simple language, `F` is that context. And (A->B) is a single-argument function. // Int -> Float oneArgFn(x) = x + 1.1 // List of Int -> List of
by mjburgess 4y ago
In my simple language, `F` is that context. And (A->B) is a single-argument function.
// Int -> Float
oneArgFn(x) = x + 1.1
// List of Int -> List of Float
ctxOneArgFn(xs) = ListFunctor(oneArgFn, xs) //ie., map()
- shikoba 4y agoYou're just reducing my idea to a specific case. You missed the generalized idea.
- reuben364 4y agoSingle-argument doesn't capture the difference between functor and applicative. ex1 :: Functor f => f (Int, Int) -> f Int ex1 = map (uncurry (+)) Applies a multi-argument function within a functor. What applicative allows you do is take a product of contexts to a context of products, and lift a value to a context. pure :: a -> f a zip :: (Applicative f) => (f a, f b) -> f (a, b) This can then be used to make ex1 into a multi-argument function of contexts, which is not the same as (uncurry (+)) being a multi-argument function ex2 :: (Functor f) => (f Int, f Int) -> f Int ex2 = ex1 . zip
- mjburgess 4y agoSure, it's a particular interpretation of `(f a, f b) -> f (a, b)` (a, b) is an a -> b (f a, f b) is an f a -> f b Applicative, over an above this, is really just useful when you have (f a, f b, f c, ..)