Constraining a function argument in an interface

烂漫一生 提交于 2019-12-04 13:39:43
Cactus

Your interface actually has two parameters: a and f. But f should be enough to pick an implementation:

interface Num a => Color (a : Type) (f : a -> Type) | f where

f here is called a determining parameter.

Here's a nonsensical full example:

import Data.Fin

interface Num a => Color (a : Type) (f : a -> Type) | f where
  foo : (x : a) -> f (1 + x)

Color Nat Fin where
  foo _ = FZ

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