Syntax 是否可以在idris中的函数定义中使用保护?

Syntax 是否可以在idris中的函数定义中使用保护?,syntax,pattern-matching,idris,guard-clause,Syntax,Pattern Matching,Idris,Guard Clause,在哈斯凯尔,人们可以这样写: containsTen::Num a => Eq a => [a] -> Bool containsTen (x : y : xs) | x + y == 10 = True | otherwise = False 如果不使用Idris,是否可以在Idris中编写等价的代码(我的实际情况比上面的更复杂)?Idris没有与haskell完全相同的模式保护。有一个with子句在语法上类似(但更强大,因为它支持存在依赖类型时的匹配):

在哈斯凯尔,人们可以这样写:

containsTen::Num a => Eq a => [a] -> Bool
containsTen (x : y : xs)
    | x + y == 10 = True
    | otherwise = False

如果不使用
Idris,是否可以在Idris中编写等价的代码(我的实际情况比上面的更复杂)?

Idris没有与haskell完全相同的模式保护。有一个with子句在语法上类似(但更强大,因为它支持存在依赖类型时的匹配):


您可以查看部分7视图和“with”规则

,这与示例Haskell中的guards不同,后者允许使用
| x+y==10…|func(x*y+52)>42=…
containsTen : Num a => List a -> Bool
containsTen (x :: y :: xs) with (x + y)
    | 10 = True
    | _  = False