我试图弄清楚 \\
Haskell 中的含义是什么?
我有一个程序在编译时可以完美运行,这意味着它\\
是一个内置函数,因为它没有在程序的任何地方定义。但是,在 GHCi 中,如果我尝试以相同的方式使用它,我会收到一条错误消息,指出它不在范围内。
它在每种情况下都意味着什么特别的东西吗?
这是我的代码;
module Main where
import Data.List
numbersA = [1, 105, 103, 7, 4, 102, 3, 101, 107, 8, 9]
numbersB = [6, 9, 7, 8, 1, 5, 3, 2, 4]
type Number = Integer
type Run = [Number]
extractRuns :: [Number] -> [Run]
extractRuns [] = []
extractRuns xs = run : extractRuns xs'
where run = buildRun (head xs) (tail xs)
xs' = xs \\ run
buildRun :: Number -> [Number] -> Run
buildRun seed numbers
| endRun = [seed]
| otherwise = seed : buildRun seed' numbers'
where endRun = successors == []
successors = filter (.#. seed) numbers
numbers' = numbers \\ [seed]
seed' = head successors
(.#.) :: Number -> Number -> Bool
x .#. y = x /= y && abs (x - y) < 10
runs = extractRuns numbersA
main = print runs