microparsec
microparsec copied to clipboard
Useful functor, applicative and monad stuff
Functor stuff:
- [ ]
fmap
/<$>
(equivalent) - [ ]
<$
(can be defined usingfmap
)(<$) :: 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<*>
andfmap
) - [ ]
>>
is the same as*>
- [ ]
return
is the same aspure
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
.