File: Fac.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 (14 lines) | stat: -rw-r--r-- 375 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=contracts #-}

-- Defining factorial numbers:

-- Specification: the usual recursive definition
fac'spec n = if n==0 then 1 else n * fac'spec (n-1)

-- The input should be non-negative:
fac'pre n = n>=0
-- The result should be positive:
fac'post _ v = v>0

-- An implementation using Prelude operations:
fac n = foldr (*) 1 [1..n]