[Haskell-cafe] induction on type-level Nat

Henning Thielemann lemming at henning-thielemann.de
Mon Jan 16 11:46:33 UTC 2023


On Mon, 16 Jan 2023, Henning Thielemann wrote:

> Alternative approach with a GADT:
>
> data T n a where
>   End :: T 0 a
>   Cons :: a -> T n a -> T (n+1) a
>
> ...
>
> If I add the constraint (1<=n+1) to Cons then the testEnd warning 
> disappears.


This definition looks less stupid and works, too:

data T n a where
    End :: T 0 a
    Cons :: (1<=n) => a -> T (n-1) a -> T n a


More information about the Haskell-Cafe mailing list