I would like to do this:
data Foo n = Foo $(tuple n Integer)
and thus allow
x :: Foo 3
x = Foo (1, 2, 3)
y :: Foo 5
y = Foo (5, 4, 3, 2, 1)
Currently I have simply
data Foo = Foo [Integer]
which can be made to work, but throws away a lot of nice compile-time checking. I’ll be making a few different Foo data objects, and each will have a fixed number of foos throughout its lifespan, and it feels silly to not be able to check that in the type system.
Is this possible in haskell?
How about
So that way you can do
Or, if you want something a bit closer to your original syntax, try
TypeFamilies:Or with even more magic (
TypeOperators,MultiParamTypeClasses, andFlexibleInstance, oh my!):