问题
What is the syntax to constrain a function argument in an interface which takes a function? I tried:
interface Num a => Color (f : a -> Type) where
defs...
But it says the Name a is not bound in interface...
回答1:
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
来源:https://stackoverflow.com/questions/36803228/constraining-a-function-argument-in-an-interface