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

Typeclass functions in parametrized modules do not work

jespercockx opened this issue · comments

Even with my PR #304, there still seems to be a problem with the compilation of typeclass instances in parametrized modules (whether the parameters are erased or not). Here's an example:

open import Haskell.Prelude

module InstanceBug (@0 X : Set) where

record Class (a : Set) : Set where
  field
    foo : a  a
open Class {{...}} public

{-# COMPILE AGDA2HS Class class #-}

instance
  ClassInt : Class Int
  ClassInt .foo = _+ 1

{-# COMPILE AGDA2HS ClassInt #-}

test : Int
test = foo 41

{-# COMPILE AGDA2HS test #-}

The error message:

No instance of type Class Int was found in scope.

With -vtc.instance:50 we get an idea of the reason:

checkCandidateForMeta
  t    = Class Int
  t'   = (@0 X : Set) → Class Int
  term = ClassInt
instance search: checking (@0 X : Set) → Class Int <= Class Int
} (exception)
candidate failed type check: /home/jesper/agda-libs/agda-core/src/Agda/Core/InstanceBug.agda:19,1-5
                             (@0 X : Set) → Class Int !=< Class Int

The module parameter X has become an explicit argument to the instance, which means it does not play well with the check we do for canonicity.