【发布时间】:2018-10-18 09:43:50
【问题描述】:
您好,我想知道是否可以在特定位置为方法提供参数,以便进一步使用point-free-notation:
readData::Text->[Int]
readData =catMaybes . maybeValues where
maybeValues=mvalues.split.filterText
filterText::Text->[Char]->Text
filterText tx chars=Data.Text.filter (\x -> not (x `elem` chars)) tx
我怎样才能只向filterText 提供2-nd 参数?像这样:
filterText "astr" 其中astr 是[Char] 参数(第二个位置)。
一般来说,当有一个方法mymethod par1 par2 par3 时我可以使用它吗:mymethod par2 并以某种方式绑定第二个论据不是第一个。
【问题讨论】:
-
您可以为此使用
flip:hackage.haskell.org/package/base-4.12.0.0/docs/… -
定义
filterText :: [Char] -> Text -> Text,问题解决。出于同样的原因,filter将谓词而不是要过滤的列表作为其第一个参数。过滤条件与过滤过程的关系比被过滤的东西更紧密,所以它是函数的 参数。 -
换句话说,条件定义了过滤器:给定
[Char],你会得到一个Text -> Text类型的函数来过滤它的输入。
标签: haskell pointfree partial-application