10

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.

1 Answer 1

13

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).

3
  • 5
    Oh that was the issue! That does make sense, '(' will get parsed as a character of course.
    – Clinton
    Aug 29, 2017 at 6:14
  • 4
    @Clinton, here's a side tip: you will likely find it very useful to define Fst and Snd type families, and it can be important to use silly-looking constraints like x ~ '(Fst x, Snd x).
    – dfeuer
    Aug 29, 2017 at 9:23
  • 1
    @dfeuer: yep, already made a package for that a few months ago, I'll just update it to include type level tuples:: hackage.haskell.org/package/indextype-0.2.0.0
    – Clinton
    Aug 29, 2017 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.