Article View: comp.lang.misc
Article #4823Polymorphic Type Systems: some unsolved problems
From: kdmoen
Date: Fri, 24 Jul 1987 03:38
Date: Fri, 24 Jul 1987 03:38
52 lines
2743 bytes
2743 bytes
I've been researching strongly typed, polymorphic languages for my thesis.
Although the problems of defining such polymorphic functions as 'identity'
(which maps a value of any type onto itself) and 'sort' (which sorts
an array of any length and any base type) are well understood,
it seems to me that there are many interesting and well defined
polymorphic functions which cannot be easily expressed in currently
existing polymorphic type systems.
Here is a partial list of difficult to define polymorphic functions.
I would greatly appreciate additions to this list, or sample code
that shows how to define any of these functions in your favourite
strongly typed, polymorphic programming language.
1) Write a single function 'twice' such that
twice(f, x) = f(f(x))
for any function f and value x for which this makes sense.
2) Define a function similar to the 'printf' function in the C
library, except that it is fully type checked.
3) Define a function 'apply' such that
apply(f, arglist)
calls the function 'f' with 'arglist' as an argument list,
for any function f, and any argument list that can legal be
passed to it.
4) Define a function called 'curry' which maps functions onto functions.
Curry maps functions with 0 or 1 arguments onto themselves,
and maps functions with 2 or more arguments onto Curried versions
of these functions. For example, it maps a function of type
"(T1, T2) -> R" onto a function of type "T1 -> T2 -> R". Similarly, it maps
"(T1, T2, T3) -> R" onto "T1 -> T2 -> T3 -> R", etc.
5) Define a function called 'uncurry' which is more or less the inverse
of curry.
6) Suppose that 'array N of T' is the type of a one dimensional array
of N elements of type T. Define a polymorphic function that
can accept an argument with one of the following types:
T
array N1 of T
array N1 of (array N2 of T)
array N1 of (array N2 of (array N3 of T))
...etc, ad infinitum
7) Define a single function that can accept an argument whose type
is either T1 or T2.
--
Doug Moen
University of Waterloo Computer Graphics Lab
UUCP: {ihnp4,watmath}!watcgl!kdmoen
INTERNET: kdmoen@cgl.waterloo.edu
Technical Details
Message-ID:
<1506@watcgl.waterloo.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!watcgl!kdmoenShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!watcgl!kdmoen From: kdmoen@watcgl.UUCP Newsgroups: comp.lang.misc Subject: Polymorphic Type Systems: some unsolved problems Message-ID: <1506@watcgl.waterloo.edu> Date: Thu, 23-Jul-87 23:38:56 EDT Article-I.D.: watcgl.1506 Posted: Thu Jul 23 23:38:56 1987 Date-Received: Sat, 25-Jul-87 11:21:10 EDT Reply-To: kdmoen@watcgl.UUCP (Doug Moen) Organization: U of Waterloo, Ontario Lines: 52