https://github.com/JacquesCarette/hol-light
Raw File
Tip revision: b27a524086caf73530b7c2c5da1b237d3539f143 authored by Jacques Carette on 24 August 2020, 14:18:07 UTC
Merge pull request #35 from sjjs7/final-changes
Tip revision: b27a524
funpow.doc
\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
back to top