我正在尝试从paper编译一些Haskell代码。 来自paper的相关文本描述和列表如下。
文字描述
“ 我们将AFFORDANCES引入为QUALITIES的子类,并示例性地建立模型 作为步步入城的一种AFFORDANCES。 QUALITIES的构造函数要求像攀爬能力这样的质量始终与其宿主一起定义。清单1中显示了AFFORDANCES和Climbability的实现。....清单1中指定的AFFORDANCES类提供了规范 如何在Haskell中编写负担能力。爬坡度实现此规范。“
列出1
class (QUALITIES affordance physicalEndurant, PHYSICAL_ENDURANTS physicalEndurant) => AFFORDANCES affordance physicalEndurant
data PHYSICAL_OBJECTS step => Climbability step = Climbability step
instance QUALITIES Climbability Step
instance AFFORDANCES Climbability Step
按现状显示清单1 缺少一些定义,这些定义已添加到清单2 中的代码中。
清单2
{-# LANGUAGE MultiParamTypeClasses, DatatypeContexts,FlexibleInstances #-}
data Step = Step
class PHYSICAL_ENDURANTS physicalEndurant where
class PHYSICAL_OBJECTS physicalEndurant where
class QUALITIES affordance physicalEndurant where
instance PHYSICAL_ENDURANTS (Climbability Step) where
instance PHYSICAL_ENDURANTS Step where
class (QUALITIES affordance physicalEndurant,PHYSICAL_ENDURANTS physicalEndurant) => AFFORDANCES affordance physicalEndurant
data PHYSICAL_OBJECTS step => Climbability step = Climbability step
-- extra arguments
instance QUALITIES (Climbability Step) Step
instance AFFORDANCES (Climbability Step) Step
但是要编译 Listing 2 ,我必须通过向QUALITIES和AFFORDANCES实例添加额外的参数来更改 Listing 1 。我是否缺少某种方法来从文件中获取原始代码进行编译?
答案 0 :(得分:3)
您需要告诉编译器期望类affordance
和QUALITIES
中的AFFORDANCES
参数是类型构造函数,换句话说,具有类型* -> *
而不是类型*
。
如果您将{-# LANGUAGE KindSignatures #-}
添加到扩展名中,则可以使用该签名对QUALITIES
进行注释,其余的将跟随:
{-# LANGUAGE MultiParamTypeClasses, DatatypeContexts, FlexibleInstances, KindSignatures #-}
data Step = Step
class PHYSICAL_ENDURANTS physicalEndurant where
class PHYSICAL_OBJECTS physicalEndurant where
class QUALITIES (affordance :: * -> *) physicalEndurant where
instance PHYSICAL_ENDURANTS Step where
class ( QUALITIES affordance physicalEndurant
, PHYSICAL_ENDURANTS physicalEndurant
) => AFFORDANCES affordance physicalEndurant
data PHYSICAL_OBJECTS step => Climbability step = Climbability step
instance QUALITIES Climbability Step
instance AFFORDANCES Climbability Step