我有以下功能
type Assignment = [(Ref, Val)]
predi2 :: [(Val,Val)] -> Ref -> Ref -> (Maybe Assignment -> [Maybe Assignment])
predi2 f k1 k2 = \ma -> case ma of
Nothing -> [Nothing]
Just a -> case lookup k1 a of
Nothing -> [Nothing]
Just e1 -> case lookup k2 a of
Nothing -> [Nothing]
Just e2 -> if elem (e1, e2) f
then [Just a]
else []
鉴于 Maybe 的所有实例,我想我可以在 Maybe monad 中将其简化为更简单的东西:
predi2 :: [(Val,Val)] -> Ref -> Ref -> (Maybe Assignment -> [Maybe Assignment])
predi2 f k1 k2 = [\ma -> do
a <- ma
e1 <- lookup k1 a
e2 <- lookup k2 a
if elem (e1, e2) f then (return a) else ???]
但我的问题是最后的 else,我不需要返回任何东西。
这是我的问题:是否有可能以 [fa] = [] 的方式返回任何内容?