{-# LANGUAGE UndecidableInstances #-}
module Symparsec.Parser.Functor
( type (<$>), type (<$), type ($>)
) where
import Symparsec.Parser.Common
import DeFun.Function ( type ConstSym1 )
type (<$>) :: (a ~> b) -> PParser a -> PParser b
infixl 4 <$>
data (<$>) f p s
type instance App (f <$> p) s = FmapEnd f (p @@ s)
type family FmapEnd f rep where
FmapEnd f ('Reply (OK a) s) = 'Reply (OK (f @@ a)) s
FmapEnd f ('Reply (Err e) s) = 'Reply (Err e) s
type (<$) :: a -> PParser b -> PParser a
infixl 4 <$
type a <$ p = ConstSym1 a <$> p
type ($>) :: PParser a -> b -> PParser b
infixl 4 $>
type p $> a = ConstSym1 a <$> p