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:
“No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.”
—André Breton (18961966)
“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)
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)