Conversation
| | isEq1Constrained ty = preludeEq1 l r | ||
| | otherwise = preludeEq l r | ||
|
|
||
| isEq1Constrained (TypeApp f _) = any (\Constraint{..} -> constraintArgs == [f]) deps |
There was a problem hiding this comment.
Whoops, need to check what the constraint is for here!
|
I was thinking the derived instances would just look like |
That's what I'm proposing for the cases there is an |
Can you elaborate? I'm not sure what you mean. |
|
So in the code I have here, if there's an data Foo f a
= Foo (f Int) a
| Bar (f String) a
| Baz (f a)You can just derive |
|
Another option might be to define That would be like the trick of using Another option could be to use Let me think about this a bit more though. |
I don't think I follow you there? How could introducing a bunch of extra type-juggling stuff like You don't really need |
|
Unless we had pattern synonyms that is, that's the only thing that would make the |
I just meant less compiler code, but it's not a big deal, I'm just thinking about other possible approaches. I think this is a fine approach. I would rather case on the syntax of the terms than the syntax of the constraint context, if possible, which is why I suggested looking for applications of a type variable to some other type. |
|
@garyb What do you think about the idea of using Also, I think it would be cool to add an example for |
I think we might run into trouble with that - I don't think it's possible to make every type constructor |
|
Not really the point, I know, but http://try.purescript.org/?gist=375025e006ceccd9975f89279e347a78 (I think you really don't need the |
|
Oh! Cool, I didn't think of that, and I tried for quite a while to come up with something too 😕 How would we make this work then? I would have thought the |
Yes, it'll be needed. I just want to explore options, and usually these things have been directed by the structure of the types, not the context, so I just wanted to go over pros and cons. |
|
So, if we were doing this based on the kind of types, would it be a case of using newtype Weird a f = Weird (f a)
data MySum a
= Value a
| CouldBe (Maybe a)
| HowAbout (Either a String)
| Fuse (Coyoneda MySum a)
| Pointless (Weird a MySum)If we derived
? |
|
I'm suggesting only using |
|
Hello, I'm Gary, and I miss extremely obvious points sometimes. |
|
I've not forgotten about this one, I'll be working on it again soon. |
|
What's left to do here? 🙂 Implementing |
|
Will revive shortly. |
Resolves #2702
Well, just
Eq1deriving so far... thought I'd open this for discussion before proceeding.The implementation is a little janky perhaps, I'm not sure how else we could approach this, without having information about the instances the other types have already. Instead of examining the constraints on the instance, ideally we'd check the environment to see whether there's an
Eq1instance for the thing we're comparing, and switch based on that - obviously we can't do that right now though.If the current approach seems acceptable enough for now I'll do the same for
Ord1. Maybe also should look at doing something likeeq1 = eqif both instances are being defined together, to cut down on the amount of code that is generated (will have to examine the instance constraints a bit for this I guess).