Próbuję dekonstruować monadę IResult
z attoparsec na kilka kawałków. Oto IResult
Partiality Monad Transformator
data IResult t r = Fail t [String] String
| Partial (t -> IResult t r)
| Done t r
to czuje się jak to powinno być kombinacją efektów „stronniczość” i niepowodzenie. Jeśli brak jest reprezentowane tylko Either ([String], String)
następnie stronniczość może być
data Partiality t a = Now a | Later (t -> Partiality t a)
instance Monad (Partiality t) where
return = pure
(Now a) >>= f = f a
(Later go) >>= f = Later $ \t -> go t >>= f
class MonadPartial t m where
feed :: t -> m a -> m a
final :: m a -> Bool
instance MonadPartial t (Partiality t) where
feed _ (Now a) = Now a
feed t (Later go) = go t
final (Now _) = True
final (Later _) = False
(który staje się jego imiennik z a paper by Danielsson podczas korzystania Partiality()
)
mogę użyć Partiality
jako monady bazowej, ale jest tam PartialityT
monada transformator?
Jaka jest twoja monadowa instancja dla 'Partiality t'? –
Dodano do głównego pytania. –