简体   繁体   English

Haskell中的文字

[英]The kind literal in Haskell

As I know, the -> has kind *->*->* , and the ((->) r) has kind *->* . 据我所知, ->有种类*->*->* ,而((->) r)有种类*->*

Assuming there is a type (a->b->c) , is there a way to represent the (a->b->) ? 假设有一个类型(a->b->c) ,有没有办法表示(a->b->)

I tried ((->) a ((->) b)) but it's error. 我试过((->) a ((->) b))但这是错误的。

I tried: 我试过了:

type Kab a b c = (a -> b -> c) -- it is ok

But it is failed to use the Kab in instance declaration: 但它未能在实例声明中使用Kab

instance KClass (Kab a b) where -- error

The only way I found that works is declare a data : 我发现有效的唯一方法是声明一个data

data Kab a b c = Kab (a -> b -> c)
instance KClass (Kab a b) where ..

But if I use the data, I have to unwrap the Kab , while my idea is to implement a KClass on native function type. 但是如果我使用数据,我必须解开Kab ,而我的想法是在本机函数类型上实现KClass。

So how to do it? 那怎么办呢?

It can't be done, unfortunately. 不幸的是,它无法完成。

One might wish for "type-level lambdas" (let's write them /\\ ); 人们可能希望“类型级lambdas”(让我们写它们/\\ ); then you would be able to write forall a b. /\\c. a -> b -> c 然后你就可以写出forall a b. /\\c. a -> b -> c forall a b. /\\c. a -> b -> c forall a b. /\\c. a -> b -> c to denote this. forall a b. /\\c. a -> b -> c表示这一点。 This would be a really handy feature, and there has been much study into type systems that allow this, but the price you pay is that type inference becomes undecidable. 这将是一个非常方便的功能,并且已经对类型系统进行了大量研究,但是您付出的代价是类型推断变得不可判定。 So the Haskell committee decided to skip it. 所以Haskell委员会决定跳过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM