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"

4 Responses to “Lifting (Haskell addendum)”

  1. Tom Says:

    Isn’t that just an applicative functor?

  2. Tony Morris Says:

    Yes.

  3. beroal Says:

    Isn’t that just an applicative functor?
    Actually we do not know, because no axioms are given. It may be anything. ;)

  4. Eyal Lotem Says:

    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

Leave a Reply