Skip to content
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

IsoHKD for composite's field type. #142

Open
locallycompact opened this issue Aug 27, 2020 · 1 comment
Open

IsoHKD for composite's field type. #142

locallycompact opened this issue Aug 27, 2020 · 1 comment

Comments

@locallycompact
Copy link

locallycompact commented Aug 27, 2020

Hi. I'm working downstream at https://github.com/ConferOpenSource/composite and trying to use the :-> operator in XRec expressions. I was able to get currying working by defining.

instance KnownSymbol s => IsoHKD Identity (s :-> a) where
  type HKD Identity (s :-> a) = a
  unHKD = Identity . Val
  toHKD (Identity (Val x)) = x

However this isn't particularly good, because this is against a different Identity declaration so it coincidentally doesn't conflict. However if I try to do for example this HKD which is what I'm using.

instance Functor m => IsoHKD (ReaderT r m) a where
  type HKD (ReaderT r m) a = r -> m a
  unHKD f = ReaderT $ f
  toHKD (ReaderT f) = f

instance Functor m => IsoHKD (ReaderT r m) (s :-> a) where
  type HKD (ReaderT r m) (s :-> a) = r -> m a
  unHKD f = ReaderT $ f
  toHKD (ReaderT f) = f

Then I get an overlapping instance error.

/home/lc/Source/gitlab.com/shakebook-site/shakebook-lib/test/Spec.hs:90:8: error:
    Conflicting family instance declarations:
      HKD (ReaderT r m) a = r -> m a -- Defined at test/Spec.hs:90:8
      HKD (ReaderT r m) (s :-> a) = r -> m a
        -- Defined at test/Spec.hs:95:8
   |        
90 |   type HKD (ReaderT r m) a = r -> m a

I can't simply copy the ELField example because the constructor for :-> is not a pair, and is defined like

newtype (:->) (s :: Symbol) a = Val { getVal :: a }

So defining

instance KnownSymbol s => IsoHKD ((:->) s) a where
  type HKD ((:->) s) a = a        
  unHKD x = Val x
  toHKD (Val x) = x

isn't actually the right behaviour because the type is not actually part of the functor, it's part of the record field. Is there a right way to do this?

@acowley
Copy link
Contributor

acowley commented Oct 1, 2020

This looks similar to cases where we use something like a type family PayloadType. Iirc, the idea there is specifically to deal with this kind of problem by special casing ElField because of how it involves complicating the record field type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants