Re: Optimizing "counting" GADTs

2016-06-18 Thread Matthew Pickering
Great stuff guys! I updated the post with your code. David, you raise two valid points. I don't have anything else to add to them at this time but it is stuff that I think about. On Sat, Jun 18, 2016 at 8:21 PM, Edward Z. Yang wrote: > Excerpts from David Feuer's message of 2016-06-18 19:47:54 -

Re: Optimizing "counting" GADTs

2016-06-18 Thread Edward Z. Yang
Excerpts from David Feuer's message of 2016-06-18 19:47:54 -0700: > I would think the provided equalities could be constructed in a view > pattern, possibly using unsafeCoerce. Yes, this does work. {-# LANGUAGE KindSignatures #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE PatternSynonyms

Re: Optimizing "counting" GADTs

2016-06-18 Thread David Feuer
I would think the provided equalities could be constructed in a view pattern, possibly using unsafeCoerce. Dictionaries are harder to come by, but reflection might be an option. My two biggest gripes about pattern synonyms are really 1. The constraints for "constructor" application are forced to b

Re: Optimizing "counting" GADTs

2016-06-18 Thread Matthew Pickering
David, Carter, It would be nice to use pattern synonyms for this task but they do not work quite as expected as they don't cause type refinement. I quickly assembled this note to explain why. http://mpickering.github.io/posts/2016-06-18-why-no-refinement.html Matt On Fri, May 27, 2016 at 4:50

Re: Inferring instance constraints with DeriveAnyClass

2016-06-18 Thread José Pedro Magalhães
On Sat, Jun 18, 2016 at 12:51 PM, Simon Peyton Jones wrote: > > > But no need to look at the data type’s constructors, as deriving(Functor) > does. > Yes, that's right. I believe we've used the "derive Functor" strategy for inferring constraints simply because all generic functions (over Generi

RE: Inferring instance constraints with DeriveAnyClass

2016-06-18 Thread Simon Peyton Jones
Yes, but none of that has anything to do with a walk over the data type, as deriving(Functor) does! You are right that what we need is the result of simplifying the instantiated constraint (Generic [a], GC (Rep [a])) Simplify that constraint (simplifyDeriv does that), including

Re: Inferring instance constraints with DeriveAnyClass

2016-06-18 Thread José Pedro Magalhães
I still don't think you can do it just from the default method's type. A typical case is the following: class C a where op :: a -> Int default op :: (Generic a, GC (Rep a)) => a -> Int When giving an instance C [a], you might well find out that you need C a =>, but this is not something you c