Curry: Example Programs
Here is a collection of (small) Curry programs.
References to larger applications can be found
here.
Usually, each program contains
some example goals at the end in order to see its
intended application.
The programs are sorted by the main language features they use
so that people interested in the various features of Curry
can look at these examples:
- rev.curry:
list concatenation and naive reverse
- higher.curry:
some standard higher-order functions: map and foldr
- quicksort.curry:
functional quicksort based on filtering the smaller and larger elements
- qsortlet.curry:
quicksort based on splitting the unsorted list into a pair of lists
with smaller and larger elements
- inflists.curry:
functions defined on infinite lists, like fib and primes
- EscherHigher.curry:
implementation of module "Higher" from the Escher report
- Nats.curry:
a basic example: natural numbers are represented as S-terms
and the substraction between numbers is defined by reversing
the addition
- family_fun.curry:
a database for family relationships (functional logic style)
- family_nd.curry:
a database for family relationships (functional logic style
with non-deterministic operations)
- horseman.curry:
a puzzle from equational logic programming (solving questions like
"How many men and horses have 8 heads and 20 feet?")
- First.curry:
lazy functional logic programming with infinite lists
- Last.curry:
compute the last element of a list using a flexible append function
(i.e., inverting list concatenation)
- Member.curry:
list membership defined by a single conditional rule based on
a flexible append function (i.e., inverting list concatenation)
- mergesort.curry:
merge sort: sorting two lists by merging the sorted first
and second half of the list
- assembler.curry:
a one-pass assembler:
translation of a sequence of arbitrary jump-instructions into machine code
where logical variables are used to resolve forward jump addresses
- nondetfunc.curry:
some "classical" examples for non-deterministic operations
like non-deterministic list insertion, permutation,
and permutation sort
- family_nd.curry:
a database for family relationships (functional logic style
with non-deterministic operations)
- colormap_nd.curry:
graph coloring with non-deterministic operations
exploiting the demand-driven search due to lazy evaluation in Curry
- colormap.curry:
map coloring with test-and-generate
(corresponds to logic programming with delays)
- digit.curry:
small example for the use of arithmetic functions acting
as passive constraints
- rigidadd.curry:
small example from the POPL'97 paper for the evaluation
with residuation: the addition of natural numbers acts as
a passive constraint waiting for the instantiation of is arguments
- see also all examples for passive constraints
- infresiduate.curry:
an example for a potential disadvantage of residuation [Hanus JLP'95]:
with residuation, the program has an infinite search space
but with narrowing, the search space is finite
- Account.curry:
concurrent object-oriented programming: a bank account implemented
as an active object ("account server")
- iodemo.curry:
some demos of the monadic I/O concept
- Diamond.curry:
printing a regular diamond of numbers on the standard output
(an adaptation from the Prolog programming contest at JICSLP'98 in Manchester)
- arithseq.curry:
some simple examples for the arithmetic sequence notation
- multgen.curry:
a few examples for list comprehensions with multiple generators
- psort.curry:
an implementation of permutation sort using list comprehensions
- default.lcurry:
an implementation of Haskell-like default rules with list comprehensions
- ModConc.curry:
a module defining list concatenation several times to be important
by the example modules below
- UseConc1.curry:
a module importing module
ModConc
- UseConc2.curry:
a module importing module
ModConc
qualified
in order to avoid name conflicts
Here are a few examples that are implementations of
programs from John Lloyd's papers on Escher.
- EscherPerm.curry:
module "Permute" from new Escher report
(computation of permutations with a concatentation and a split
function)
- EscherHigher.curry:
implementation of module "Higher" from the Escher report
- EscherCond.curry:
module "Conditional" from the Escher report
(check membership in a list)
- relational.curry:
module "Relational" from the Escher report
(computing with relations)
Back to Homepage of Curry
Michael Hanus