我想跟踪终止以下内容与计算列表长度的版本之间的差异。我有一个递归和一个尾递归。不知怎的,我在ghci(见下文)中运行时遇到了问题
-- 4-1 a) Laenge einer Liste --
import Criterion.Main
main :: IO ()
main = defaultMain [
bgroup "myList" [ bench "1" $ whnf myList [1]
, bench "2" $ whnf myList [1,2]
, bench "3" $ whnf myList [1,2,3]
, bench "4" $ whnf myList [1,2,3,4]
, bench "10" $ whnf myList [1,2,3,4,5,6,7,8,9,10]
, bench "20" $ whnf myList [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
]
bgroup "myListner" [ bench "1" $ whnf myListner [1]
, bench "2" $ whnf myLister [1,2]
, bench "3" $ whnf myListner [1,2,3]
, bench "4" $ whnf myListner [1,2,3,4]
, bench "10" $ whnf myListner [1,2,3,4,5,6,7,8,9,10]
, bench "20" $ whnf myListner [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
]
]
--endrekursiv
myList:: [a]->Integer
myList []=0
myList (x:xs)= myHelpList 1 xs
where
myHelpList:: Integer-> [a]->Integer
myHelpList acc [] = acc
myHelpList acc (x:xs) = myHelpList (acc+1) xs
--nicht endrekursiv
myListner::[a]->Integer
myListner []=0
myListner (x:xs)= 1+ myList xs
Ghci回归:
laenge.hs:3:8:
Could not find module ‘Criterion.Main’
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Prelude>
任何人都可以帮助我吗?