考虑以下多行字符串S
:如何在Haskell中创建这些字符串匹配函数?
apple
banana berry
cantelope
我想写/定位Haskell函数,我将在这篇文章or-match
和and-match
调用。下面是他们应该做的一些例子:
or-match S ("apple","berry")
{- should return the two line string:
apple
banana berry
-}
and-match S ("apple", "berry") --should return the empty string, or something like "No matches."
and-match S ("banana" "berry") --should return a single line containing "banana berry"
在上面的例子中,我使用的类型(String, String)
为or-match
和and-match
域参数。我不确定这是最好的方式,但我可能想使用两个以上的参数。虽然我是Haskell的新手,但我不确定如何使任意长度的元组成为函数的参数。
总之,这篇文章的整体问题:我如何or-match
和哈斯克尔and-match
,使得对于每这些功能域参数是任意长度的元组(或某些类型的,允许任意一个搜索长度)?
没有必要自己实现'hasSubString';标准库将其作为'isInfixOf',并且Hackage上存在更高效的版本。 –