【发布时间】:2017-12-15 06:29:29
【问题描述】:
对于一个作业,给出了以下代码
-- 2. Index
class Index i where
findEntry :: Eq k => k -> i k -> Maybe Entry
empty :: Eq k => i k
singleton :: Eq k => k -> Entry -> i k
(<+>) :: Eq k => i k -> i k -> i k
-- a. Complete the definition of Assoc
data Assoc k
= MkAssoc [(k,Entry)]
deriving (Eq,Show)
-- b. Complete the instance of Index for Assoc
instance Index Assoc where
我现在完全卡在问题 2.b 上。如何使空和 findEntry 和其他东西?索引中的“k”来自哪里?为什么某些函数的输出是(i k)?那甚至都不是类型。
【问题讨论】:
-
k是与Assoc绑定的k类型参数,所以k是“key”类型。
标签: haskell types functional-programming