Lifting (Haskell addendum)
A follow-on from Lifting. A port of the Scala code to Haskell follows.
class Lift f where lift0 :: a -> f a lift1 :: (a -> b) -> f a -> f b lift1 = ap . lift0 lift2 :: (a -> b -> c) -> f a -> f b -> f c lift2 f = ap . lift1 f lift3 :: (a -> b -> c -> d) -> f a -> f b -> f c -> f d lift3 f a = ap . lift2 f a ap :: f (a -> b) -> f a -> f b -- scala.List instance Lift [] where lift0 = error "todo" ap = error "todo" -- scala.Option instance Lift Maybe where lift0 = error "todo" ap = error "todo" -- scala.Either[R, _] instance Lift (Either r) where lift0 = error "todo" ap = error "todo" -- scala.Functior1[R, _] instance Lift ((->) r) where lift0 = error "todo" ap = error "todo"
August 19th, 2011 at 4:38 pm
Isn’t that just an applicative functor?
August 19th, 2011 at 4:59 pm
Yes.
September 27th, 2011 at 8:21 pm
Isn’t that just an applicative functor?
Actually we do not know, because no axioms are given. It may be anything.
October 18th, 2011 at 10:20 pm
I’d suggest separating it into the relevant classes.
Lift0 (Pointed):
class Lift0 f where lift0 :: a -> f a
Lift1 (Functor):
class Lift1 f where lift1 :: (a -> b) -> f a -> f b
Lift2 (ap):
class Lift1 f => Lift2 f where lift2 :: (a -> b -> c) -> f a -> f b -> f c
Lift (Applicative):
class (Lift0 f, Lift2 f) => Lift f where