-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MonoApply #159
Comments
I have to admit that I don't really understand this proposal, sorry.
…On Wed, Jan 24, 2018 at 7:22 PM, Erik Schnetter ***@***.***> wrote:
It seems that a type class
class MonoFunctor mono => MonoApply mono where
liftF2 :: (Element mono -> Element mono -> Element mono) -> mono -> mono -> mono
would be convenient to have.
Since you can't store functions in a MonoFunctor, it seems that the
obvious generalizations liftF3 etc. need to be defined manually, which is
inconvenient.
An alternative and more generic definition could be
class MonoFunctor mono => MonoCotraversable mono where
cotraverse :: (Foldable f, Functor f) => (f (Element mono) -> Element mono) -> f mono -> mono
I don't know whether the Functor constraint here is sufficient -- I've
seen examples where others defined Cotraversable with a stronger Comonad
constraint on f instead.
An example use case would be
data IntList = IntList [Int]
instance MonoFunctor IntList where
type Element IntList = Int
ofmap f (IntList xs) = IntList (map f xs)
instance MonoApply IntList where
oliftF2 f (IntList xs) (IntList ys) = IntList (zipWith f xs ys)
max2 = oliftF2 max
instance MonoCotraversable IntList where
ocotraverse f xss = IntList $ map f (sequenceA xss)
maxMany = ocotraverse maximum
Haskell has traverse f = sequenceA . fmap f. What I'm suggesting here is
similar to cotraverse f = fmap f . sequenceA. Since MonoTraversable by
construction can't offer sequenceA, it seems this should be provided
explicitly.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#159>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AADBBzcY4jyUvIkh7j7w9uYk3jf-H9Baks5tN2bGgaJpZM4Rrnq8>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that a type class
would be convenient to have.
Since you can't store functions in a
MonoFunctor
, it seems that the obvious generalizationsliftF3
etc. need to be defined manually, which is inconvenient.An alternative and more generic definition could be
I don't know whether the
Functor
constraint here is sufficient -- I've seen examples where others definedCotraversable
with a strongerComonad
constraint onf
instead.An example use case would be
Haskell has
traverse f = sequenceA . fmap f
. What I'm suggesting here is similar tocotraverse f = fmap f . sequenceA
. SinceMonoTraversable
by construction can't offersequenceA
, it seems this should be provided explicitly.The text was updated successfully, but these errors were encountered: