Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kind Polymorphic Tuples

Tags:

haskell

I noticed with PolyKinds and DataKinds the following compiles fine:

data Pair a b
data Test = Test
type Test2 = Pair 'Test 'Test

However:

type Test3 = ('Test, 'Test)

fails, presumably as (,) is not kind polymorphic, which makes sense as it makes values out of it's type arguments and you can't make values of types which are not of kind *.

Is there a library that has kind polymorphic tuples (to save me reinventing the wheel)?

I do realise that that unlike real tuples, kind polymorphic tuples will only exist on the type level, but that's all I need for my purposes.

like image 639
Clinton Avatar asked Aug 29 '17 06:08

Clinton


1 Answers

If you are already using DataKinds, you should just use the promoted version of built-in tuple constructor, as opposed to the type constructor:

type Test3 = '( 'Test, 'Test)

This has kind (Test, Test).

Note there must be a space between ( and '; '('Test, 'Test) is a syntax error (a necessary edge case in the parser).

like image 186
user2407038 Avatar answered Sep 21 '22 16:09

user2407038