<div dir="ltr">Hi haskell-cafe,<div><br></div><div>so for fun and profit I was trying to make a non-empty list data type, where the size of the non-empty prefix would be known for the type-system with the following code, but it fails with an error "No instance for (Functor (NonEmpty * a)) ..." for the last line. To me it seems that all should be known, but something must be missing..</div>
<div><br></div><div>data Nat = Zero | Succ Nat</div><div><br></div><div><div>data family NonEmpty (n :: Nat) a</div><div>data instance NonEmpty Zero a = Tail [a]</div><div>data instance NonEmpty (Succ n) a = Head a (NonEmpty n a)</div>
<div><br></div><div>instance Functor (NonEmpty Zero) where</div><div> fmap f (Tail xs) = Tail (fmap f xs)</div><div>instance Functor (NonEmpty (Succ a)) where</div><div> fmap f (Head x xs) = Head (f x) (fmap f xs)</div>
<div><br></div>-- <br>Markus Läll<br>
</div></div>