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

Newtype constructor erroneously removed #320

Open
bwbush opened this issue May 8, 2024 · 2 comments
Open

Newtype constructor erroneously removed #320

bwbush opened this issue May 8, 2024 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@bwbush
Copy link

bwbush commented May 8, 2024

Agda

record Hash (a : Set) : Set where
  constructor MakeHash
  field hashBytes : ByteString
open Hash public
{-# COMPILE AGDA2HS Hash newtype deriving (Generic, Show) #-}

instance
  iMaybeHashable : ⦃ i : Hashable a ⦄  Hashable (Maybe a)
  iMaybeHashable {{_}} .hash Nothing = MakeHash (hashBytes (hash iUnitHashable tt))
  iMaybeHashable {{i}} .hash (Just x) = MakeHash (hashBytes (hash iPairHashable (tt , x)))
{-# COMPILE AGDA2HS iMaybeHashable #-}

becomes Haskell

newtype Hash a = MakeHash{hashBytes :: ByteString}
                   deriving (Generic, Show)

instance (Hashable a) => Hashable (Maybe a) where
    hash Nothing = hash ()
    hash (Just x) = hash ((), x)

even though MakeHash . hashBytes != id since in this case we had MakeHash :: ByteString -> Maybe a but hashBytes :: () -> ByteString etc.

@jespercockx
Copy link
Member

So the problem here seems to be that Agda itself eta-contracts MakeHask (hashBytes x) to x, even when the parameters of the constructor and the projection are different, possibly caused by agda/agda#2732. I'm not sure if there is much we can do to fix this on the agda2hs side. As a workaround, you could add a no-eta-equality clause to the record definition, which should be enough to stop Agda from eta-contracting.

@jespercockx jespercockx added the bug Something isn't working label May 9, 2024
@jespercockx
Copy link
Member

Perhaps we should just enforce that records that are compiled to Haskell data types always have eta-equality disabled.

@jespercockx jespercockx added this to the 1.4 milestone Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants