-
Notifications
You must be signed in to change notification settings - Fork 563
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
Automatically generate instances for Data.Typeable #2243
Comments
I would vote for waiting until kind polymorphism is present, as otherwise we'd need a potentially infinite number of variations on But I don't know, maybe that is unnecessary? Can I ask what |
Ah, I hadn't thought through the fact each type variable needs to be of kind My particular interest in I considered using |
Excellent points regarding |
Just wanted to let folks know that I've been working on this -- that is, having the compiler automatically generate And, it turns out that the lack of polymorphic kinds doesn't make much difference to what the compiler needs to do. The code on the Purescript side could be simplified in the presence of polymorphic kinds, but what the compiler generates wouldn't change radically. (Note that the code on the Purescript side is quite different from what is in What I'm working on at the moment is rebasing my work-in-progress on the 'fundeps' branch. Aside from being necessary, I think that with fundeps I can parameterize the Perhaps very little of that will make sense without seeing my code, but I just wanted to give a quick update on what I'm working on. I hope to post some code for people to look at next week. |
@rgrempel I'm interested to see what you've got in the works for derived How does your use case of storing data in the DOM compare to something like I've never actually used Another small point - if we did have compiler-supported deriving, it would be good to have a minimal implementation of a |
Is this the kind of stuff that could eventually allow us to write user defined type class deriving mechanisms? For example, deriving Functor, Foldable, & Traversable - which is obviously not possible with Generic. |
@LiamGoodacre, I'm not sure. It would allow you to "introspect" on the types at run-time in a way that is distinct from @paf31, the comparison with Now, there is nothing in To put it another way, given some So, what As for my particular use case, I don't need an alternate representation of the Purescript value -- I'm happy to be handed back the Purescript value exactly as it is. All I need is to be able to know, at run time, whether it is the same type as something else I now have, even though I can't arrange for the compiler to know that (as would be the usual way of doing things). In fact, I actually have a couple of (for me) even more motivating use cases since then. One is my https://github.com/rgrempel/purescript-exists-eq package, which allows you to test for equality even where you need to forget the type. This, in turn, enables some interesting stuff in purescript-equatable-functions to do with comparing functions that have been partially applied. And that, in turn, is the basis for something I haven't published yet, Philosophically, the paper that has influenced my thinking on Anyway, I'll try to post some actual code later this week, or at least as soon as I can. And I completely understand that it will need pretty serious review. |
Just a quick update. I've been experimenting with using functional dependencies, tagless final, and a form of "Church encoding" to do some things that one might do with GADTs, if we had them. It's a bit of overkill, but I'm finding it fascinating, so I'm seeing how far I can push it. Basically, I'm trying to "forget" some type parameters, like we can do with Anyway, that's why I haven't pushed the code yet -- I'm still experimenting. |
If you want a use case, |
I think I'll close this issue ... I might want to revive this exploration at some point, but my current attitude (with a bit more experience) is that it's almost always a nice idea to explore alternatives to Also, such work-in-progress as I had is quite stale now -- it would need some pretty thorough revisiting. And, the original motivating use case for me is something I'm now preferring to handle a different way. |
@rgrempel I'm curious about the alternative way you found for solving your problem. Is it the stuff in your Elm-in-PureScript project which you talked about in your PS Unscripted - Simulating GADTs for JSON decoder talk? There, you used Coyoneda and Leibniz for type equality. |
Yes, it’s that In part. lt’s also that I no longer am leaving bare Purescript values attached to the DOM somewhere — that had been the original use-case for wanting to know whether the “next” value was of the same type. Now, I’m handling the memory of the previous value as part of the data type within Purescript itself, so have different techniques available. |
I've been doing some work updating Data.Typeable.
One logical next step would be to have the compiler automatically derive instances for
Data.Typeable
. It is (at least conceptually) trivial, since it is basically an encoding of the type, which the compiler knows. In fact, it is more reliable to have the complier derive the instance than anything else, since the compiler has the most reliable knowledge of the type. (That is, human implementation could get out of sync with the actual type).In fact, GHC now does even more than support
deriving Typeable
. It actually automatically generates an instance when needed, even without any explicit invocation ofderiving
. This would be especially desirable in Purescript, given the prohibition of orphan instances. Otherwise, every single module would need to add aderiving Typeable
(or one would have to use the usual workarounds, such as anewtype
etc.).So, my question is this: if I were to implement automatic instance generation for
Data.Typeable
, is that something that would be considered desirable (and possibly mergeable)? Clearly, one wouldn't want to support this kind of thing in the compiler for very many purposes, but I think thatData.Typeable
is arguably pretty fundamental.One additional consideration is that
Data.Typeable
will probably change considerably when "kind polymorphism" (#1763) is available, in a manner similar to the equivalent changes in Haskell. I suppose that one could delay implementing automatic instance generation until kind polymorphism is available. However, I'm not sure whether there is any compelling reason to wait. That is, it may turn out that there is a technical reason why automatic instance generation depends on kind polymorphism, but it isn't obviously so (at least, it's not obvious to me).The text was updated successfully, but these errors were encountered: