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

add newtype utils #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add newtype utils #70

wants to merge 2 commits into from

Conversation

stevemao
Copy link

When I was working with opaleyes, I found my self needing these simple utils when I follow tomjaguarpaw/haskell-opaleye#570 (comment) to be more type safe.

I have added the examples how I use them

Please let me know if these are not necessary and we can achieve the same result using any existing functions.

Thanks

@tomjaguarpaw
Copy link
Owner

Thanks! My first reaction is that a lot of these should be done by giving the Newtype instance a Traversable instance too, and then just using traverse and related functions. Perhaps Traversable should be a superclass constraint of Newtype, actually. I'll have a bit more of a think and get back to you.

@stevemao
Copy link
Author

Thanks.

I think it would be good if any instance of Newtype would become instance of Traversable automatically. I'm not sure how to use superclass constraint to achieve that "automatically"

I have tried this

{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE IncoherentInstances  #-}
{-# LANGUAGE UndecidableInstances #-}

instance (Newtype t) => Functor t where
    fmap = mapNewtype

But these extensions give me some trouble in the codebase

• No instance for (Data.Profunctor.Product.Newtype.Newtype IO)
        arising from a use of ‘P.embedToFinal’

(I'm using Polysemy but I have no idea how that's related).

@tomjaguarpaw
Copy link
Owner

The correct way to do it would be to change the definition of Newtype to

class Traversable t => Newtype t where
    ...

and then you can just derive Traversable for all your Newtype instances. That's a breaking change though, so I'm somewhat reluctant to make it. Maybe it's fine.

@tomjaguarpaw
Copy link
Owner

Do you have any public code that shows how you use them? I think in general that just using the Traversable instance of the corresponding type would be the right thing to do, but it would be helpful to see some examples to confirm that.

@stevemao
Copy link
Author

stevemao commented Nov 3, 2023

Do you have any public code that shows how you use them?

No. But I'm happy to do screen sharing to show you

@stevemao
Copy link
Author

One thing you could do is

  • release a minor version with these utils, without any new instances.
  • once we've made the decisions how to create these new instances, release a major version.

@tomjaguarpaw
Copy link
Owner

Sorry, this is on my TODO list to look at but realistically it's going to be a very long time before I get to it.

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

Successfully merging this pull request may close these issues.

2 participants