🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #2680

Re: On whether C has first-class composable functions

#2680
From: Darren New
Date: Mon, 21 Jan 1991 19:06
56 lines
3739 bytes
In article <BBC.91Jan21120817@sicilia.rice.edu> you write:
>When I think of "function composition", I usually think of it in a
>mathematical sense.  For such a function "compose(f,g)", the
>requirements on the two parameters that come to mind are that the
>domain of "f" matches the range of "g", that the domain of
>"compose(f,g)" matches the domain of "g", and that the range of
>"compose(f,g)" matches the range of "f".  (The definitions of
>"matches" in the previous sentence is left as an exercise to the
>reader.) On this mathematical bent, it also seems reasonable to
>require that the functions "f" and "g" are pure functions, though I
>doubt this additional restriction will make my challenge any easier.

Hmmm... I don't know that I've ever seen a mathematical system where
the functions are not pure, since I've always seen functions described
as a set of <domain-element, range-element>.  I've also always seen
compositions, as well as "apply" and other functions that take
functions, either defined only to work on integer|->integer functions
with the assumption that both the input and output integers are
unlimited in range and may be coding something else (like a program or
a pair of integers), or as being a class of functions all with the same
(or no) name (somewhat like overloaded functions), or functions that
map functions onto other functions of the same type (as in type
theory). (I'm rusty on the type theory, so no flames, please.) Since C
has neither unlimited integers nor general overloaded functions, I
don't know that "the definition of matches" (left to the reader) should
not exclude certain restrictions. For example, you say "the range of
compose(f,g) matches the range of f". If I take "matches" to mean
"assignment compatible in C" then it becomes trivial to show that for
each f with a different return type you will need a different compose.
Similarly with the range of g. Hence, the "matches" is why restricting
compose to work only on integer identity functions won't work, as there
are many f's and g's which take one integer and return one integer
(i.e., with the same ranges and domains), and assumedly any compose
which works on one should work on the others. However, the fact that
you cannot change the range of f and still have the range of compose
"match" it does not seem to be saying that functional composition is
impossible in C.  (Maybe it isn't, but I would not consider this to be
the reason.)


>>I'm one of those who thinks that "first-class" is relative to what
>>you can do with other things in the same language, so I think you're
>>changing the rules here.
>
>What rules have I changing in issuing my challenge?
>That all challenges must have trivial solutions?

No, that first-class functions must be able to accept and return arbitrary
types, whereas first-class variables need not.
	     -- Darren
-- 
--- Darren New --- Grad Student --- CIS --- Univ. of Delaware ---
----- Network Protocols, Graphics, Programming Languages, 
      Formal Description Techniques (esp. Estelle), Coffee, Amigas -----
              =+=+=+ Let GROPE be an N-tuple where ... +=+=+=
Technical Details
Message-ID: <42327@nigel.ee.udel.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!wuarchive!udel!ee.udel.edu
References: <BBC.91Jan12160209@sicilia.rice.edu> <298@smds.UUCP> <BBC.91Jan21120817@sicilia.rice.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!wuarchive!udel!ee.udel.edu
From: new@ee.udel.edu (Darren New)
Newsgroups: comp.lang.misc
Subject: Re: On whether C has first-class composable functions
Message-ID: <42327@nigel.ee.udel.edu>
Date: 21 Jan 91 19:06:21 GMT
References: <BBC.91Jan12160209@sicilia.rice.edu> <298@smds.UUCP> <BBC.91Jan21120817@sicilia.rice.edu>
Sender: usenet@ee.udel.edu
Organization: University of Delaware
Lines: 56
Nntp-Posting-Host: estelle.ee.udel.edu