我尝试手动评估belongs 'a' ['a', 'b', 'c']
其中:
cuts :: [a] -> [([a],[a])]
cuts xs = zipWith splitAt [0..length xs] (repeat xs)
belongs x = any ((==x) . head . snd) . init . cuts
首先评估cuts ['a', 'b', 'c'] = [("","abc"),("a","bc"),("ab","c"),("abc","")]
然后我将init
应用于cuts
的输出:
init [("","abc"),("a","bc"),("ab","c"),("abc","")] = [("","abc"),("a","bc"),("ab","c")]
然后我对GHCi如何继续评估感到困惑。
PS:请注意belongs
与Prelude.elem
具有相同的语义。