Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The kind literal in Haskell

Tags:

haskell

As I know, the -> has kind *->*->*, and the ((->) r) has kind *->*.

Assuming there is a type (a->b->c), is there a way to represent the (a->b->)?

I tried ((->) a ((->) b)) but it's error.

I tried:

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

But it is failed to use the Kab in instance declaration:

instance KClass (Kab a b) where -- error

The only way I found that works is declare a 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.

So how to do it?

like image 508
Liao Pengyu Avatar asked May 16 '15 03:05

Liao Pengyu


People also ask

What is a type literal?

A literal is a more concrete sub-type of a collective type. What this means is that "Hello World" is a string , but a string is not "Hello World" inside the type system.

How do you identify a literal type?

The values assigned to each constant variable are referred to as the literals. Generally, both terms, constants, and literals are used interchangeably. For example, “const int = 5;“, is a constant expression and the value 5 is referred to as a constant integer literal.

What is string literal type?

The string literal type allows you to specify a set of possible string values for a variable, only those string values can be assigned to a variable. TypeScript throws a compile-time error if one tries to assign a value to the variable that isn't defined by the string literal type.


1 Answers

It can't be done, unfortunately.

One might wish for "type-level lambdas" (let's write them /\); then you would be able to write forall a b. /\c. a -> b -> c to denote this. 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.

like image 169
Daniel Wagner Avatar answered Oct 17 '22 17:10

Daniel Wagner