Skip to content
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

Exposing functions using defaults from a Monoid constraint #124

Open
mcallisterjp opened this issue Sep 27, 2019 · 3 comments
Open

Exposing functions using defaults from a Monoid constraint #124

mcallisterjp opened this issue Sep 27, 2019 · 3 comments

Comments

@mcallisterjp
Copy link

There are various places in this module where it might be useful to have padding for containers that happen to contain Monoidal values be automatically defaulted by mempty.

I'm particularly thinking of something like:
padZipEmpty :: (Semialign f, Monoid a, Monoid b) => f a -> f b -> f (a,b)
padZipWithEmpty :: (Semialign f, Monoid a, Monoid b) => (a -> b -> c) -> f a -> f b -> f c

Perhaps it might also be worth exposing an explicit default version too:
padZipDef :: (Semialign f) => a -> b -> f a -> f b -> f (a,b)

Let me know what you think. I'm happy to implement this and send a PR if you like the idea.

@mcallisterjp
Copy link
Author

I now notice padZipDef has already been suggested as alignDef by @muesli4: #94.

Happy to implement these too, using his naming or mine.

@phadej
Copy link
Collaborator

phadej commented Sep 27, 2019

I'm yet not convinced about usefulness of alignDef and alignDefWith.

Take for example:

instance (Semialign f, Semialign g) => Semialign (Compose f g) where
    alignWith f (Compose x) (Compose y) = Compose (alignWith g x y) where
        g (This ga)     = fmap (f . This) ga
        g (That gb)     = fmap (f . That) gb
        g (These ga gb) = alignWith f ga gb

alignDefWith won't be useful, though the situation feels like there is something "default" you want to do.

And to make it sure, I'm 👎 to use Monoid. Why not Default? and how to name this.

@muesli4
Copy link

muesli4 commented Sep 27, 2019

I'm yet not convinced about usefulness of alignDef and alignDefWith.

Well, I've seen this pattern a few times. But most of the time it is done by using some combination of zip and repeat. See: https://hackage.haskell.org/package/list-zip-def

In the end it's just 2 functions without any invasive change. I don't see the point in not adopting them. (The naming was just a proposal.)

alignDefWith won't be useful, though the situation feels like there is something "default" you want to do.

I don't see the point of your example. Also I would argue that you should rather point out why it shouldn't be adopted in general. Most definitions are not useful in every context, that doesn't mean they are never useful.

And to make it sure, I'm -1 to use Monoid. Why not Default? and how to name this.

Why would you ever want to limit yourself to instances of Default? I think the general case is the most important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants