File: funpow.doc

package info (click to toggle)
hol-light 20170109-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 36,568 kB
  • ctags: 8,549
  • sloc: ml: 540,018; cpp: 439; lisp: 286; java: 279; makefile: 262; sh: 229; yacc: 108; perl: 78; ansic: 57; sed: 39
file content (33 lines) | stat: -rw-r--r-- 736 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
\DOC funpow

\TYPE {funpow : int -> ('a -> 'a) -> 'a -> 'a}

\SYNOPSIS
Iterates a function a fixed number of times.

\DESCRIBE
{funpow n f x} applies {f} to {x}, {n} times, giving the result {f (f ... (f
x)...)} where the number of {f}'s is {n}. {funpow 0 f x} returns {x}. If {n} is
negative, it is treated as zero.

\FAILURE
{funpow n f x} fails if any of the {n} applications of f fail.

\EXAMPLE
Apply {tl} three times to a list:
{
  # funpow 3 tl [1;2;3;4;5];;
  val it : int list = [4; 5]
}
\noindent Apply {tl} zero times:
{
  # funpow 0 tl [1;2;3;4;5];;
  val it : int list = [1; 2; 3; 4; 5]
}
\noindent Apply {tl} six times to a list of only five elements:
{
  # funpow 6 tl [1;2;3;4;5];;
  Exception: Failure "tl".
}

\ENDDOC