microparsec icon indicating copy to clipboard operation
microparsec copied to clipboard

Useful functor, applicative and monad stuff

Open schneiderfelipe opened this issue 3 years ago • 0 comments

Functor stuff:

  • [ ] fmap / <$> (equivalent)
  • [ ] <$ (can be defined using fmap)
    (<$)        :: a -> f b -> f a
    (<$)        =  fmap . const
    

Applicative stuff:

  • [ ] pure
  • [ ] <*> / liftA2 (equivalent)
    liftA2 :: (a -> b -> c) -> f a -> f b -> f c
    liftA2 f x = (<*>) (fmap f x)
    
  • [ ] *>
    (*>) :: f a -> f b -> f b
    a1 *> a2 = (id <$ a1) <*> a2
    
  • [ ] <*
    (<*) :: f a -> f b -> f a
    (<*) = liftA2 const
    

Monad stuff:

  • [ ] >>= (can be used to define both <*> and fmap)
  • [ ] >> is the same as *>
  • [ ] return is the same as pure

Note one

In practice, most of the functions above can be more efficiently implemented than suggested above.

Note two

When we get mature concepts, this will be much easier. Let's use duck-typing for now, with auto.

schneiderfelipe avatar Jun 21 '21 20:06 schneiderfelipe