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

Internal error using DefaultMonoid

jakobn-ai opened this issue · comments

Maybe a duplicate of #264. It's also possible that a shorter example shows the same issue 😬.

{-# OPTIONS --erasure #-}
open import Haskell.Prelude
open import Haskell.Prim.Monoid
open import Haskell.Prim.Foldable

data MyData (a : Set) : Set where
  Nothing : MyData a
{-# COMPILE AGDA2HS MyData #-}

-- notice this does not occur with other classes such as Foldable
myDataDefaultFoldable : DefaultFoldable MyData
DefaultFoldable.foldMap myDataDefaultFoldable _ _ = mempty

instance
  MyDataFoldable : Foldable MyData
  MyDataFoldable = record {DefaultFoldable myDataDefaultFoldable}
{-# COMPILE AGDA2HS MyDataFoldable #-}

-- need to create instance for semigroup first
-- (requires explicitly typed function AFAICT)
_><_ : {a : Set} -> MyData a -> MyData a -> MyData a
_ >< _ = Nothing
{-# COMPILE AGDA2HS _><_ #-}

instance
  MyDataSemigroup : Semigroup (MyData a)
  MyDataSemigroup ._<>_ = _><_
{-# COMPILE AGDA2HS MyDataSemigroup #-}

myDataDefaultMonoid : DefaultMonoid (MyData a)
DefaultMonoid.mempty myDataDefaultMonoid = Nothing

instance
  MyDataMonoid : Monoid (MyData a)
  MyDataMonoid = record {DefaultMonoid myDataDefaultMonoid}
{-# COMPILE AGDA2HS MyDataMonoid #-}

gives

Compiling top-level type {a : Set} → DefaultMonoid (MyData a)
An internal error has occurred. Please report this as a bug.
Location of the error: __IMPOSSIBLE__, called at src/full/Agda/TypeChecking/Substitute.hs:230:38 in Agda-2.6.5-323613b2730ee27d1c3eda526550c172af1cb88bfacbd5c214c68a9e31a9a557:Agda.TypeChecking.Substitute

This also happens when basing on Agda-master.

It seems this is fixed by my PR #304. So you are lucky @omelkonian :)