0

I want to track the difference of time for termination of the following to versions calculating the length of a list. I have got one recursive and one tail recursive. Somehow i have got a problem when running in ghci (See below)

-- 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 returns:

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>

Can anyone help me with that?

Mauritius
  • 265
  • 1
  • 8
  • 23
  • Criterion is installed – Mauritius May 01 '16 at 10:43
  • how did you install it (as you can see GHCi don't think it is) – Random Dev May 01 '16 at 10:59
  • Mauritiuss-MacBook-Pro:~ Mauritius$ cabal install -j criterion Resolving dependencies... All the requested packages are already installed: criterion-1.1.1.0 Use --reinstall if you want to reinstall anyway. Mauritiuss-MacBook-Pro:~ Mauritius$ – Mauritius May 01 '16 at 11:02
  • are you using `cabal sandboxes` or `stack` then you need to adapt the ghci call to `cabal repl` or `stack ghci` – epsilonhalbe May 01 '16 at 11:06
  • if you are using outdated versions of ghc/cabal you might find https://stackoverflow.com/questions/17014270/how-can-i-use-ghci-with-the-new-cabal-1-17-sandboxes interesting – epsilonhalbe May 01 '16 at 11:07
  • also note running criterion in ghci is a bad idea - usually when you are doing profiling you are compiling with optimizations! – epsilonhalbe May 01 '16 at 11:09

0 Answers0