[ create a new paste ] login | about

Link: http://codepad.org/FgRsOFi7    [ raw code | output | fork ]

kinaba - Haskell, pasted on Jun 23:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import System

fib = 0:0:zipWith (+) fib (tail fib)

at0 = (!!)

at1 xs n = impl xs n 0
  where impl (x:xs) 0 _ = x
        impl (x:xs) n _ = impl xs (n-1) $ x

at2 xs n = impl xs n 0
  where impl (x:xs) 0 _ = x
        impl (x:xs) n _ = impl xs (n-1) $! x

main = do
  args <- getArgs
  print $ (at2 fib) $ read $ args !! 0


Output:
1
2

Program error: Prelude.!!: index too large


Create a new paste based on this one


Comments: