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

Generic generic #68

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

Generic generic #68

wants to merge 2 commits into from

Conversation

mikeplus64
Copy link

The reason this is useful is to be able to combine Reps of different types, and pretend that they are actually a Generic type on their own.

@phadej
Copy link
Contributor

phadej commented Jul 4, 2018

nice!

@phadej
Copy link
Contributor

phadej commented Jul 4, 2018

I'd rather do more general instance:

instance (All SListI a, f ~ I) => Generic (SOP f a) where
   ....

I don't think that Generic (SOP f a) would make any sense for anything else than f ~ I.

@mikeplus64
Copy link
Author

Done :-)

@kosmikus
Copy link
Member

kosmikus commented Jul 5, 2018

I've been thinking about this instance in the past, but I've always been hesitating because it isn't actually giving you a generic representation of a SOP. Could you explain your use case in more detail?

@mikeplus64
Copy link
Author

My exact use-case: squeal-postgresql allows users to run insertions of arbitrary types so long as their Rep matches the expected Rep for the particular table. However, you don't always actually want your Haskell types to have, e.g., internal IDs in them. That is, if you have a type:

data Location = Location { locType :: Text, locCentre :: Coord, ... }

the corresponding table in your schema may have a serial primary key. With this instance, we can keep the idiomatic Location type (i.e., don't add a strange "ID" field to it), but still be able to use it for queries/insertions; instead of having traversePrepared_ (insertRow_ #location (Set (param @1) As #locId :* ...)) [UglyLocation { locId = XXX, ..}], we can have traversePrepared_ (insertRow_ #location (Set (param @1) As #locId :* ...)) [XXX :* from Location {..}].

@kosmikus
Copy link
Member

I see. I think I'd feel slightly more comfortable to define a different newtype-wrapper around SOP and provide the instance for that. This should cover your use case. I'm not sure though. I could certainly be convinced to just accept your PR as it is now. My primary worry that it might become easier to confuse original types with their representations if we add this kind of instance.

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.

None yet

3 participants