相关疑难解决方法(0)

在Haskell中执行`and`和`或`表示布尔函数

我刚写了以下两个函数:

fand :: (a -> Bool) -> (a -> Bool) -> a -> Bool
fand f1 f2 x = (f1 x) && (f2 x)

f_or :: (a -> Bool) -> (a -> Bool) -> a -> Bool
f_or f1 f2 x = (f1 x) || (f2 x)
Run Code Online (Sandbox Code Playgroud)

它们可能用于组合两个布尔函数的值,例如:

import Text.ParserCombinators.Parsec
import Data.Char

nameChar = satisfy (isLetter `f_or` isDigit)
Run Code Online (Sandbox Code Playgroud)

看了这两个函数后,我意识到它们非常有用.以至于我现在怀疑它们是否包含在标准库中,或者更可能是使用现有函数有一种干净的方法来执行此操作.

这样做的"正确"方法是什么?

haskell combinators pointfree

42
推荐指数
3
解决办法
5万
查看次数

标签 统计

combinators ×1

haskell ×1

pointfree ×1