Mic*_*ron 2 haskell types functional-programming lazy-evaluation purely-functional
我有以下数据可以发货或不发货:
data LaserCollisionResult = NoCollision | LaserToLaserCollision Ship | LaserToShipCollision Ship deriving (Eq, Show)
然后,稍后,我试图检查LaserCollisionResult是否为LaserToLaserCollision类型,但是我收到错误.我的[lambda]功能是这样的:
laserPaths' = map (\(p,r) -> if r == LaserToLaserCollision then doSomethingWith p else p) $ zip laserPaths laserCollisionResults
我得到的错误是:
Couldn't match type 'LaserCollisionResult' with 'Ship -> LaserCollisionResult'
Expected type: [Ship -> LaserCollisionResult]
Actual type: [LaserCollisionResult]
In the second argument of 'zip', namely laserCollisionResults.
如何检查laserCollisionResults中的LaserCollisionResult是否属于LaserToLaserCollision类型?
替换你的lambda
(\(p,r) -> case r of {LaserToLaserCollision _ -> doSomethingWith p; _ -> p})
顺便说一句,为此您不需要派生Eq实例.
| 归档时间: | 
 | 
| 查看次数: | 71 次 | 
| 最近记录: |