【发布时间】:2014-05-30 19:10:13
【问题描述】:
我正在尝试编写函数
fromList :: [e] -> Vector n e
fromList [] = Nil
fromList (x:xs) = x :| fromList xs
使用这个向量的定义
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 :|
但是,Haskell 给出了错误
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.
我相信由于(:|) 的类型签名而引发了错误。
有没有办法绕过这个错误?
【问题讨论】:
标签: haskell