Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upfurther mysteries of unification with constrained higher-rank types #2865
Comments
This comment has been minimized.
This comment has been minimized.
|
Something tells me that the evil part is in the following step:
|
This comment has been minimized.
This comment has been minimized.
|
Why not cons :: forall s s' a. Pred s s' => a -> List s' a -> List s a? Edit: this is the problem, I think. |
This comment has been minimized.
This comment has been minimized.
|
Here is another way you can solve this: http://try.purescript.org/?gist=7a7f8b65e0db2757508dfee38ddb07ed This is safe because the functional dependency |
This comment has been minimized.
This comment has been minimized.
|
When I copy-paste your suggestion, I still get the same error, I think because now the definition of How does one make the (I will mess around with As for the other example, thank you. I see that it works. The On a more broad note, I wonder if you think these kinds of things are a worthwhile avenue to pursue, generally speaking, or if I'm likely to run into a lot of dead ends and cryptic error messages. Lots of questions, I know... But I do find your responses here very helpful. |
This comment has been minimized.
This comment has been minimized.
|
If you want data List s a = Nil | Cons a (forall r. (forall s'. Pred s s' => List s' a -> r) -> r)(http://try.purescript.org/?gist=351b6a383d27fb0396ec286591f2f887) but it's not as efficient and it doesn't have the same representation at runtime. That's why I think this sort of thing is worth pursuing, but coming up with a good API with good type errors can be challenging :) |
This comment has been minimized.
This comment has been minimized.
|
Oh wow... Okay, thanks for the tip on that. I wouldn't have thought of it. I'm going to close this. This has been very educational :). If you have any additional external resources for learning these kind of tricks that you would recommend off the top of your head, I'd very much appreciate them. Obviously Haskell-land would be the place to turn, but it seems that FunDeps are no longer the tool of choice for higher-rank tricks over there. |
matthewleon commentedApr 24, 2017
•
edited
I think this is a bug, but I'm not 100% sure. The bug might just be in my understanding of the compiler's unification strategy for these types. If so, I apologize and will post further queries in a more appropriate forum. As it stands, though, the behavior below is at least... Perplexing.
Compilation errors on the definition of
singleton. Here is the verbose error:Not only does it seem to me that these types should unify, but that
D0is the only type the could unify, due to thePredconstraint applied toD1. I have a slight suspicion that my brain might be clouded by Prolog, though.