3
在使用函數的接口中約束函數參數的語法是什麼?我想:在接口中約束函數參數
interface Num a => Color (f : a -> Type) where
defs...
但它說,Name a is not bound in interface...
在使用函數的接口中約束函數參數的語法是什麼?我想:在接口中約束函數參數
interface Num a => Color (f : a -> Type) where
defs...
但它說,Name a is not bound in interface...
你interface
實際上有兩個參數:a
和f
。但是,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
噢噢我有兩個參數的接口,但我沒有意識到我可以用'| f'強迫一個人來決定,這是非常好的。 – ScarletAmaranth