[gambit-list] Re: New types

david rush kumoyuki at gmail.com
Mon Feb 14 23:18:49 EST 2005


On Mon, 14 Feb 2005 21:13:11 -0600, Bill Richter
<richter at math.northwestern.edu> wrote:
>    A functor is I think just a first-class function, either named or
>    anonymous, e.g. a (lambda (...) ...)
> 
> Here's the mathematical definition of functor, and I'll be
> disappointed if David R can't rope this in to what he's doing:
> 
> A Category is a gadget that has both objects and morphism between
> objects.  

To this categorical pretender; this is a programmatic type. (I am
agreeing with you, just trying to translate into more pedestrian
language)

> A functor F: C ---> D is a map between 2 categories C & D preserving
> the structure.  

I was not particularly aware of the "preserving structure"
requirement; however, this is the essence of SML's module system
(which actually originated the use of the term functor in this
context), so I tend to use the term when referring to a certain style
of code modularization which uses functions parameterized over types.
Since Scheme is dynamically typed (and therefore type compatibility is
defined behaviorally), the use of functors amounts to using functions
parameterized by other type-specific functions. In Scheme, a trivial
example:

;;; NOTE: untested code, for other examples and macrology
;;; google comp.lang.scheme for functor
(define (fib-functor zero one add sub body)
   (define (fib n)
      (define (fib-rec n fn fn-1)
         (if (equal? n zero)
             fn
             (fib-rec (add n one)
                        (add fn fn-1)
                        fn)))
      (fib-rec n one one))
   (body fib))

There is quite a bit of overkill in the preceding in order to show the
most relevant points. I usually pass in a body function because it
saves the grief of using call/values to return the result category. I
also usually do not pass any of the parameters to the body function
since they will have been available in the invoking scope.

> Now I've heard that category theory has become popular (if not
> actually useful :)) in Computer Science.

Yes, having dabbled in it, I have found it to a useful source of good
ideas for code structuring. I also understand that the OO community
use category theory in their mathematical foundations. Mind you that
was over 10 years ago, and I'm sure the field has changed.

since this isn't really Gambit traffic, I would suggest any further
follow-ups go to c.l.s or private email :)

david rush
-- 
DIsruptive Technology!


More information about the Gambit-list mailing list