考慮以下多行字符串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上存在更高效的版本。 –