3

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...

ScarletAmaranth
  • 5,065
  • 2
  • 23
  • 34

1 Answers1

5

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
Benjamin Hodgson
  • 42,952
  • 15
  • 108
  • 157
Cactus
  • 27,075
  • 9
  • 69
  • 149