Mimicking Haskell canonicity (one-instance only) of typeclasses in Agda

只愿长相守 提交于 2019-12-07 02:18:32

问题


Agda's mixiture of records and the instance keyword give us behaviour similar to that of Haskell's typeclasses. Moreover, ignoring the instance keyword, we can have more than one instance for the same type --- something we cannot do in Haskell.

I am at a point where I need Haskell's one-instance only requirement, but in Agda. Is there an compiler option or some trick/heuristic to enforce this?

Right now the approach I am taking is,

record Yo (n : ℕ) : Set where
  field
    sem : (some interesting property involving n)

open Yo {{...}}

postulate UniqueYo: ∀ {n} (p q : Yo n) → p ≡ q

However, whenever I actually use UniqueYo the lack of computation leaves my goals littered with things like ...| UniqueYo p p where I'd prefer ...| refl or a full rewrite into normal form instead.

Any help is appreciated!

来源:https://stackoverflow.com/questions/36803125/mimicking-haskell-canonicity-one-instance-only-of-typeclasses-in-agda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!