在以下代码中:
ismaxl :: (Ord a) => [a] -> a -> Bool
ismaxl l x = x == maxel
where maxel = maximum l
main = do
let mylist = [1, 2, 3, 5]
let ismax = ismaxl mylist
--Is each call O(1)? Does each call remember maxel?
let c1 = ismax 1
let c2 = ismax 2
let c3 = ismax 3
let c5 = ismax 5
putStrLn (show [c1, c2, c3, c5])
偏函数是max,计算maxel吗?特别是,有人可以指出关于 Haskell 中偏函数复杂性的规则吗?编译器必须在上面的例子中只调用一次最大值吗?换句话说,部分函数是否保留了对内部 where 子句的先前调用的引用?
我有一些受 CPU 限制的代码执行不可接受,并且我正在寻找可能的错误,以推理复杂性。