agda / agda2hs

Compiling Agda code to readable Haskell

Home Page:https://agda.github.io/agda2hs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad compilation of integer literal to `int64 (Prelude.primWord64FromNat ...)`

jespercockx opened this issue · comments

I found this while looking into #251. Consider the following example:

open import Haskell.Prelude

instance
  favoriteNumber : Int
  favoriteNumber = 42
{-# COMPILE AGDA2HS favoriteNumber inline #-}

get : {{Int}}  Int
get {{x}} = x
{-# COMPILE AGDA2HS get inline #-}

test : Int
test = get
{-# COMPILE AGDA2HS test #-}

Currently agda2hs compiles this to the following:

import qualified Prelude (primWord64FromNat)

test :: Int
test = int64 (Prelude.primWord64FromNat 42)

where neither int64 nor primWord64FromNat are valid Haskell functions. The former is defined in Haskell.Prim.Int as the constructor of the Int type, while the latter comes from Agda.Builtin.Word.

I'm not sure what exactly is going on here, but something about the fact that favoriteNumber is an instance makes agda2hs trip over itself.