Coder Social home page Coder Social logo

Depend on sop-core about generics-mrsop HOT 14 CLOSED

arianvp avatar arianvp commented on September 22, 2024
Depend on sop-core

from generics-mrsop.

Comments (14)

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

We really only care about the NS and NP types. For the sake of compatibility with other libraries in the future, I think we could just import Data.SOP (NP(..)) in Generics.MRSOP.Base.NP and the same in NS.

from generics-mrsop.

arianvp avatar arianvp commented on September 22, 2024

Yes. That is exactly what I wanted to suggest :)

from generics-mrsop.

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

For the sake of documenting; this does conflict with #39 !

I'm of the opinion that #39 will eventually become obsolete once they fix GHC's bug. Nevertheless,
if the 8.8 release does not fix it, I will give a shot at #39, which will break the sop-core dependency.

from generics-mrsop.

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

In the light of the new developments in #39, which didn't solve anything, I'm a go on this suggestion!

We should organize a pull request and try to close some issues together with this refactor, so we do a single major version bump (i.e., #44 and #42 )

from generics-mrsop.

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

We have decided we will not add an extra dependency for two datatypes only.

from generics-mrsop.

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

After discussing with Andres at ICFP, I was convinced it is better to depend on sop-core than to
roll my own NS and NP datatypes.

from generics-mrsop.

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

As usual; not so straight forward. I gave it a quick go at c6bd21b but then got stuck on a typeclass hell.

Data.SOP.Constraint defines the following instances for NS and NP:

instance (All (Compose Show f) xs) => Show (NS f xs) where ...
instance (All (Compose Eq f) xs) => Eq (NS f xs) where ...

Which makes sense, but are harder to thread through generics-mrsop, where
we abstracted it differently, by the means of the showHO.

from generics-mrsop.

serras avatar serras commented on September 22, 2024

Where do the problems arise more concretely?

from generics-mrsop.

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

I'm not 100% yet; I'm trying to remove the ShowHO and EqHO typeclasses we had. I just made
them into the following constraint-synonyms:

type EqHO   f = forall x . Eq (f x)
type ShowHO f = forall x . Show (f x)

In the old Generics.MRSOP.Zippers.Deep we'd have to carry some constraint in the Ctx datatype.
I just removed the module as the shallow zippers should suffice.

I'm now trying to compile generics-mrsop-gdiff and hdiff; if I succeed on these, I'd happily drop EqHO and ShowHO and stick with the quantified constraints versions above and unify everything
with sop-core.

from generics-mrsop.

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

@serras

The process has been mainly mechanic so far; We will need to add things like
the following instance to mrsop, though.

type EqHO   f = forall x . Eq (f x)
instance (EqHO f , EqHO g) => Eq ((f :*: g) x) where
  (==) (fx :*: gx) (fy :*: gy) = fx == fy && gx == gy

from generics-mrsop.

serras avatar serras commented on September 22, 2024

I thinl you can even abstract the EqHO type as:

type HO (c :: r -> Constraint) (f :: k -> r) = forall (x :: k). c (f x)
instance (HO Eq f, HO Eq g) => Eq ((f :*: g) x) where ...

Now you don't need a different ConstraintHO for each constraint.

from generics-mrsop.

VictorCMiraldo avatar VictorCMiraldo commented on September 22, 2024

That makes sense; It's just that a good amount of code already has EqHO and ShowHO spread through it.

In any way; if I understand -XQuantifiedConstraints, this shouldn't be different from our
manual handling of higher-order though our (old) EqHO.

@serras , I got some impredicative polymorphism error right here, for which I had to pull the quantified constraints out
and distribute them by hand. Not sure if this was supposed to happen or if type annotations would fix this.

from generics-mrsop.

serras avatar serras commented on September 22, 2024

You can always define EqHO as HO Eq and keep the code the same.

Note however that -XQuantifiedConstraints sometimes asks for more than a higher-order version. In the case of something like NP, you can ask for Eq (f x) for every x in a type-level list; if you ask for forall x. Eq (f x) this requires for every x in Type.

from generics-mrsop.

serras avatar serras commented on September 22, 2024

@serras , I got some impredicative polymorphism error right here, for which I had to pull the quantified constraints out
and distribute them by hand. Not sure if this was supposed to happen or if type annotations would fix this.

Yes, there seems to be some weird things happening when you abstract over constraints with foralls. Something they "count" as quantified constraints , and everything is fine, sometimes they are rank-n types, and then GHC starts asking for impredicative polymorphism.

I guess the best solution is what you are doing: just thread the constraints by hand.

from generics-mrsop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.