I know how to define typeclasses, and after reading the definition of RawMonad
, RawMonadZero
, RawApplicative
and more, I implemented some simple type instances:
data Parser (A : Set) : Set where
MkParser : (String → List (A × String)) → Parser A
ParserMonad : RawMonad Parser
ParserMonad = record {
return = λ a → MkParser λ s → < a , s > ∷ []
; _>>=_ = λ p f → MkParser $ concatMap (tuple $ parse ∘ f) ∘ parse p
}
But when I'm trying to use ParserMonad.return
in the implementation of ParserApplicative
, I failed:
ParserApplicative : RawApplicative Parser
ParserApplicative = record {
pure = ParserMonad.return -- compile error
; _⊛_ = ...
}
My question is: how to use ParserMonad.return
to implement ParserApplicative.pure
? How can I do that or what doc should I read?