Tying to learn more about applicatives.
I have the following definitions:
class Applicative' f where
pack :: a -> f a
unpack :: f a -> a
instance Applicative' Box where
pack x = Box x
unpack (Box x) = x
instance Applicative' Bag where
pack x = Bag x
unpack (Bag x) = x
instance Applicative' Basket where
pack x = Basket x
unpack (Basket x) = x
pack1::(Applicative' f)=>(a->b)->f a->f b
pack1 fn ta = pack (fn (unpack ta))
pack2::(Applicative' f)=>(a->b->c)->f a->f b->f c
pack2 fn ta tb = pack(fn (unpack ta) (unpack tb))
What I am looking for is a way generalise this concept (something similar to sequenceA function), so it should possible to use this function (lets call it someFn) the following way:
somefn (\x->x+1) (Box 2)
Box 3
somefn (\x->\y->x+y) (Box 1) (Box 2)
Box 3
somefn (\x->\y->\z->x+y+z) (Box 1) (Box 2) (Box 3)
Box 6
Not sure how I can achieve this in Haskell.