A functor is I think just a first-class function, either named or anonymous, e.g. a (lambda (...) ...)
I think the usage here is more like "combinator", i.e. a functor with no free variables that can be combined with other combinators to create new kinds of compositions the way objects in an object-oriented program might be composed. (aka the "part-of" relationship rather than the "is-a" relationship.)
I may be putting words in David's mouth that have nothing to do with his message. 8^/
-Patrick
-----Original Message----- From: Eduardo Cavazos
What's a functor? Can you show me an example of how they are better in
some
way?
On Mon, 14 Feb 2005 09:24:59 +0530, david rush kumoyuki@gmail.com
wrote:
;; In an object system like the one I made it's much shorter:
Well, I used to think that way too. Believe me, you're on
well-trodden
ground here.
Anyway I switched to heavy use of functors because I got tired...
Afficher les réponses par date
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. We require that there there be an identity morphism 1_X between any object X and itself, and given two morphisms alpha: X ---> Y and beta: Y ---> Z, there is a composition beta * alpha : X ---> Z and this composition must be associative, i.e. gamma * (beta * alpha) = (gamma * beta) * alpha
A functor F: C ---> D is a map between 2 categories C & D preserving the structure. So for ever object X in C, we have an object F(X) in D, and for every morphism alpha: X ---> Y in C, we have a morphism F(alpha): F(X) ---> F(Y) in D and we require that F(1_X) = 1_F(X) and F(beta * alpha) = F(beta) * F(alpha)
I called a category a gadget because we don't insist that Ob(C), the collection of objects of C, form a set. If it does, then we call C a small category. One often considers large categories, such as the category of sets, morphisms being functions between sets. We do insist that the morphisms between 2 objects, written Hom_C(X, Y), is a set. If it's not a set, it means it's "too big".
Now I've heard that category theory has become popular (if not actually useful :)) in Computer Science.
On Mon, 14 Feb 2005 21:13:11 -0600, Bill Richter richter@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