agda2hs icon indicating copy to clipboard operation
agda2hs copied to clipboard

Postulates are not exported

Open bwbush opened this issue 9 months ago • 1 comments

If a type is postulated, but aliased via the COMPILE pragma, it is not exported for other modules to use.

In the example below, ByteString is not accessible from Haskell modules that import the module with this postulate.

postulate
  ByteString : Set
  emptyBS : ByteString
  concatBS : List ByteString → ByteString
  eqBS : ByteString → ByteString → Bool
{-# COMPILE GHC ByteString = type BS.ByteString #-}
{-# COMPILE GHC emptyBS = BS.empty #-}
{-# COMPILE GHC concatBS = BS.concat #-}
{-# COMPILE GHC eqBS = (==) #-}
{-# FOREIGN AGDA2HS
emptyBS :: ByteString
emptyBS = BS.empty
concatBS :: [ByteString] -> ByteString
concatBS = BS.concat
eqBS :: ByteString -> ByteString -> Bool
eqBS = (==)
#-}

bwbush avatar May 09 '24 15:05 bwbush

That's probably because Agda2hs ignores {-# COMPILE GHC … #-} pragmas? If you want Agda2hs to do something, I would expect a {-# COMPILE AGDA2HS … #-} pragma. 😅

HeinrichApfelmus avatar May 09 '24 16:05 HeinrichApfelmus

To support this properly we would need to have a dedicated pragma for indicating that an Agda postulate corresponds to an existing Haskell function, which we do not have at the moment (see https://github.com/agda/agda2hs/issues/119).

jespercockx avatar May 24 '24 12:05 jespercockx

To support this properly we would need to have a dedicated pragma for indicating that an Agda postulate corresponds to an existing Haskell function, which we do not have at the moment (see https://github.com/agda/agda2hs/issues/119).

Alternatively we could use the presence of a rewrite rule as an indicator that a symbol exists on the Haskell side.

jespercockx avatar Jun 08 '24 13:06 jespercockx

The rewrite-rule resolves the issue for the example above:

rewrites:
  - from: "<Module>.ByteString"
    to: "ByteString"
    importing: "Data.ByteString"

yveshauser avatar Jun 09 '24 12:06 yveshauser

Since we already have a supported way to do this, I'm closing this issue.

jespercockx avatar Jun 09 '24 12:06 jespercockx