我想要一個函數在一個String上使用兩次。我要解釋我想要什麼,所以我希望在問題的結尾你明白我的意思。使用函數兩次使用映射
所以我有這個功能。
foo :: String -> [String]
foo = ...
現在我想這個函數在字符串上使用兩次。因此,首先使用時應該使用給函數的字符串運行foo,而在第二次運行時應該使用第一次運行產生的[String]中的每個字符串。所以我猜想地圖是做這件事的最佳功能。 所以我得到了現在這個功能
f :: String -> [String]
f w = map foo (foo w)
但compliler給了我這個錯誤:
MyHaskell.hs:86:19:
Couldn't match type `[Char]' with `Char'
Expected type: String -> String
Actual type: String -> [String]
In the first argument of `map', namely `edits1'
In the expression: map edits1 (edits1 word)
我想這個問題是我的函數foo(字符串 - > [字符串])不奏效與地圖((a-> b) - > [a] - > [b])。
我該如何解決?
這就等於'import Control.Monad; f = foo> => foo'。 – user3237465
也與'concatMap foo相同。 foo'。 –
比'foo> => foo'解決方案的可讀性高10倍。 – alternative