在接口中约束函数参数

时间:2016-04-22 21:00:39

标签: idris

在接受函数的接口中约束函数参数的语法是什么?我试过了:

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

但它说的是Name a is not bound in interface...

1 个答案:

答案 0 :(得分:5)

您的interface实际上有两个参数:af。但是f应该足以选择implementation

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

f此处称为determining parameter

这是一个荒谬的完整例子:

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
相关问题