You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can write a similar function with a stronger constraint:
embedSeq:: (Monadm, Monadn) => (foralla.ma->SeqTna) ->SeqTma->SeqTna
embedSeq f s = f (toView s) >>=\r ->case r ofEmpty-> empty
a :< s' ->pure a <|> embedSeq f s'
Is it lawful? I haven't checked yet, but I wouldn't be surprised.
The documentation doesn't indicate any restrictions on the function passed to embed, but I wonder if it's supposed to be a monad morphism (see Gabriella439/Haskell-MMorph-Library#68). If it is, we might be able to write an instance something like this inscrutable monstrosity:
instanceMMonadSeqTwhere
embed (f ::foralla.ma->SeqTna) (SeqT m0) =SeqT$fmap go m0
wherego::forallb.m (Viewmb) ->n (Viewnb)
go m = toView (f m) >>=\r ->case r ofEmpty->pureEmptyEmpty:< s -> toView (step s)
(x :< q) :< s ->pure$ x :< (embed f q <|> step s)
step::forallb.SeqTn (Viewmb) ->SeqTnb
step s = s >>=\r ->case r ofEmpty-> empty
a :< s' ->pure a <|> embed f s'
Lawful? Sensible? No idea whatsoever.
The text was updated successfully, but these errors were encountered:
Control.Monad.Morph
has a classWe can write a similar function with a stronger constraint:
Is it lawful? I haven't checked yet, but I wouldn't be surprised.
The documentation doesn't indicate any restrictions on the function passed to
embed
, but I wonder if it's supposed to be a monad morphism (see Gabriella439/Haskell-MMorph-Library#68). If it is, we might be able to write an instance something like this inscrutable monstrosity:Lawful? Sensible? No idea whatsoever.
The text was updated successfully, but these errors were encountered: