2 Oct 2012 20:54
Strange things with type literals of kind Nat
Troels Henriksen <athas <at> sigkill.dk>
2012-10-02 18:54:39 GMT
2012-10-02 18:54:39 GMT
Consider the following definition of lists with a statically determined
minimum length.
data Nat' = Z | S Nat'
data NList (n::Nat') a where
Rest :: [a] -> NList Z a
(:>) :: a -> NList n a -> NList (S n) a
uncons :: NList (S n) a -> (a, NList n a)
uncons (x :> xs) = (x, xs)
This works fine. Now consider an implementation using the new type
literals in GHC:
data NList (n::Nat) a where
Rest :: NList 0 [a]
(:>) :: a -> NList n a -> NList (n+1) a
uncons :: NList (n+1) a -> NList n a
uncons (x :> l) = l
This gives a type error:
/home/athas/code/nonempty_lists.hs:41:19:
Could not deduce (n1 ~ n)
from the context ((n + 1) ~ (n1 + 1))
bound by a pattern with constructor
:> :: forall a (n :: Nat). a -> NList n a -> NList (n + 1) a,
in an equation for `uncons'
(Continue reading)
RSS Feed