Constraining a function argument in an interface

爱⌒轻易说出口 提交于 2019-12-06 09:00:40

问题


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

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