[英]Haskell class definition question about restrictions
class IndexSelect k (m :: k -> (* -> *) -> *) | m -> k where
type Restriction m (p :: k) :: Constraint
indexSelect :: Restriction m p => Sing (p :: k) -> Proxy m -> LocalDb f -> f (TableEntity (m p))
I'm new to the Haskell language. 我是Haskell语言的新手。 I'm having trouble deciphering the class definition in some code in the code repo at the company I just started at.
我在我刚刚开始的公司的代码库中的某些代码中解密类定义时遇到了麻烦。 What is this doing?
这是做什么的?
There is a lot going on here. 这里有很多事情要做。 I am going to start by referring you to Sections 7.6 Class and Instance Declarations , 7.7 Type Families , and 7.8.4 Explicitly-kinded qualifications of the GHC language extension documentation.
我将首先向您介绍第7.6节类和实例声明 , 7.7类型系列 ,以及7.8.4 GHC语言扩展文档的明确资格 。 (I am by no means an expert on any of these and clicked on your question hoping someone had supplied further enlightenment.)
(我绝不是任何一个问题的专家,并点击你的问题,希望有人提供进一步的启示。)
We are defining a multi-parameter type class called IndexSelect
with parameters k
and m
. 我们正在定义一个名为
IndexSelect
的多参数类型类,其参数为k
和m
。 (Multi-parameter type classes 7.6.1.1) (多参数类型7.6.1.1)
The second parameter of the class, m
, is given an explicit kind qualification: k -> (* -> *) -> *
in English m
must be a function which takes a k
and a function and returns a value. 类
m
的第二个参数给出了一个明确的类型限定: k -> (* -> *) -> *
in English m
必须是一个函数,它接受一个k
和一个函数并返回一个值。 (7.8.4 Explicitly-kinded quantification) (7.8.4显性定量)
The class has a functional dependency | m -> k
这个类有一个函数依赖
| m -> k
| m -> k
. | m -> k
。 Where the choice of m
must uniquely determine k
Given the name of this function that implies that a collection m
must have only one kind of key k
which is reasonable. m
的选择必须唯一地确定k
给定该函数的名称,这意味着集合m
必须只有一种合理的密钥k
。 (7.6.2 Functional Dependencies) (7.6.2功能依赖)
The class forms a indexed type family type Restriction m (p :: k) :: Constraint
. 该类形成索引类型族
type Restriction m (p :: k) :: Constraint
。 It appears inside a class definition so it is an associated type synonym. 它出现在类定义中,因此它是关联类型的同义词。 (7.7.2.1.1 Associated type family declarations).
(7.7.2.1.1相关类型的家庭声明)。 It takes some
m
and a p
which must be of type k
and results in a Constraint. 它需要一些
m
和一个p
,它必须是k
型并导致约束。
The class has one listed method indexSelect
which one might guess manages to extract information from a collection. 该类有一个列出的方法
indexSelect
,可能猜测该方法可以从集合中提取信息。 Without knowing what Sing
, LocalDb
and TableEntity
do I cannot say more. 不知道
Sing
, LocalDb
和TableEntity
什么,我不能多说。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.