File: Fib.curry

package info (click to toggle)
curry-tools 1.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,492 kB
  • ctags: 121
  • sloc: makefile: 470; sh: 421
file content (16 lines) | stat: -rw-r--r-- 471 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=contracts #-}

-- Fibonacci numbers specified by traditional recursive definition
-- and computed efficiently by an infinite list.

-- Specification of Fibonacci numbers:
fib'pre x = x >= 0
fib'post _ y = (y > 0)
fib'spec x | x == 0 = 0
           | x == 1 = 1
           | otherwise = fib'spec (x-1) + fib'spec (x-2)

-- Implementation of Fibonacci numbers:
fib n = fiblist 0 1 !! n
 where
  fiblist x y = x : fiblist y (x+y)