-
Notifications
You must be signed in to change notification settings - Fork 274
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
Order dependence for makeFields
#1051
Comments
Right, this is a somewhat unfortunate aspect of the way At a minimum, I think we should document this behavior. We might also consider adding a variant of
|
This could be fixed by changing the generated class for class HasA s
type A' :: Type
type Kind :: Type -> Type -> Type
a :: Kind s A' This would require changing Functional Dependencies to Type Families class HasA s a kind | s -> a kind where
a :: kind s a
instance HasA (A a) a Traversal' where
... where the instance is equivalent to: instance HasA (A a) a (forall f. Applicative f => (a -> f a) -> A a -> f (A a)) where
... Which does not compile due to: instance Applicative f => HasA (A a) a ((a -> f a) -> A a -> f (A a)) where
... The approch with the Functional Dependencies would be a lot of work. |
I'm not enthusiastic about this idea, as it would mean that writing code that is polymorphic over a f :: (HasA a, Kind s A' ~ Traversal') => ... It's possible, but in more equality constraints than I'm usually comfortable with. |
Oh I never thought of this, since I just recently started using f :: (HasA a, Kind ~ Traversal') => ... The other option would be to expand the |
I just noticed a bigger problem: getAa :: A -> a
getAa = view a |
I just tried to implement it and noticed that even with typefamilies the solution doesn't work as you must have the constrains outside the type. The only solution which could be implemented (I think) is expanding the type alias and extracting the restriction to outside the instance declaration, which, if possible, would be very cumbersome, both for the implementation and for functions polymorphic over |
My solution. $(do
makeFieldsNoPrefix ''A
makeFieldsNoPrefix ''B
) |
|
Pretty much exactly this. |
I wrote something off the mark, sorry. |
The following code does not compile, while it would if you switch the last two lines.
This is due to the first call to
makeFieldsNoPrefix
defining the classand it either containing a definition with type
Lens' s a
orTravesal' s a
.The text was updated successfully, but these errors were encountered: