Examples
A "hello world" example:
hello = writes "Hello, world!\n";The following function generates the "stream" (a.k.a. infinite list) of all prime numbers:
primes = sieve (ints 2); ints N = bin N (ints (N+1)); sieve (bin X Xs) = bin X (sieve (filter (ndivby X) Xs)); ndivby M N = N mod M <> 0;An algorithm to solve the "N queens" problem, using backtracking:
queens N = search N 1 1 ; search N I J P = write P || writes "\n" if I>N; = search N (I+1) 1 (P++) || fail if safe (I,J) P; = search N I (J+1) P if JRead more about this topic: Q (equational Programming Language)
Famous quotes containing the word examples:
“In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.”
—Michel de Montaigne (15331592)
“It is hardly to be believed how spiritual reflections when mixed with a little physics can hold peoples attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.”
—G.C. (Georg Christoph)
“No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.”
—André Breton (18961966)