I am trying to write a function
fromList :: [e] -> Vector n e
fromList [] = Nil
fromList (x:xs) = x :| fromList xs
using this vector definition
data Natural where
Zero :: Natural
Succ :: Natural -> Natural
data Vector n e where
Nil :: Vector Zero e
(:|) :: e -> Vector n e -> Vector (Succ n) e
infixr :|
However, Haskell gives an error
Couldn't match type 'Zero with 'Succ n0
Expected type: Vector n e
Actual type: Vector ('Succ n0) e
In the expression: x :| fromList xs
In an equation for `fromList': fromList (x : xs) = x :| fromList xs
Failed, modules loaded: none.
I believe the error is due to the type signature (:|).
Is there any way around this error?
source
share