[英]Replace where case of with guards
I have specific situation I've checked a link here and I was wondering if the same strategy could be applied within a where statement in haskell.我有特定的情况,我在这里检查了一个链接,我想知道是否可以在 haskell 的 where 语句中应用相同的策略。
Suppose I have a function:假设我有一个函数:
Func1:: Term -> [Term]
Func1 (Foo a b) = [ Foo a' b | a' <- Func1a ] ++ [ Foo b' a | b' <- Func1b ] ++ M
where
M = case a of
Bar v body -> [substitute var b body]
_ -> []
Is there a way to replace the case of with guards?有没有办法用警卫替换案件?
Here's how you can do it:您可以这样做:
func1 :: Term -> [Term]
func1 (Foo a b) = [ Foo a' b | a' <- func1a ] ++ [ Foo b' a | b' <- func1b ] ++ m
where
m | Bar v body <- a = [substitute v b body]
| otherwise = []
I think the main point of confusion might be that you can place the |
我认为主要的混淆点可能是你可以放置
|
immediately after m
.紧接在
m
之后。 The rest it is very similar to the answer that you already linked.其余的与您已经链接的答案非常相似。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.