【发布时间】:2023-03-06 16:43:01
【问题描述】:
我正在尝试定义一个名为byteWidth 的函数,它捕获了有关“获取特定原子类型的字节宽度”的用法。
我的第一次试用:
byteWidth : Type -> Int
byteWidth Int = 8
byteWidth Char = 1
而 Idris 编译器抱怨:“检查 byteWidth 的左侧时:左侧没有显式类型:Int”
我的第二次试用:
interface BW a where
byteWidth : a -> Int
implementation BW Int where
byteWidth _ = 8
implementation BW Char where
byteWidth _ = 1
在这种情况下,我只能像byteWidth 'a' 一样使用byteWidth,但不能使用byteWidth Char。
【问题讨论】:
标签: coq agda idris dependent-type