On 2 April 2012 01:26, Boyko Bantchev <boyk...@gmail.com> wrote:
> On 2 April 2012 01:17, Boyko Bantchev <boyk...@gmail.com> wrote:
>> I just noticed that my previous post was not stored in the
>> J forum archives in its entirety, only part of it is there.
>>
>> This is an attempt to post it as an attached file.
>
> It seems that attachments are cut off, so I am posting again, from the copy
> in my out-box, the second part of my previous post.
>
> Sorry for the inconvenience.
>

Another misterious failure .....
Ok, one more try ....

      *****second part to my previous post*****

From a categorial point of view, to each family of types as described
above, there corresponds a category (whose objects are the members of
the family).  Thus there are categories of lists, of trees, etc.
The objects of the category of lists are the types of integer-valued,
real-valued, string-valued, etc. lists.

Note that there is a one-to-one correspondence between tyconses and
categories (except the universal category), naturally established
through both being associated with the same family of types.

As any other value, functions are typed, and their types are written
f :: a -> b, meaning that the function f has a domain a and a codomain
b.  Because there can be many functions of the same signature  a -> b,
there are many arrows between any two objects in any of the categories,
the universal one or the specific.

After all this, what is a functor in Haskell?  It is a mapping, in
the above described categorial sense of the word 'functor', from the
universal category of types to any one of the specific categories.
The definition of functor is embodied in the following type class
interface:

        class Functor t where
          fmap :: (a -> b) -> (t a -> t b)

together with the axioms

        fmap id ≡ id
        fmap (f . g) ≡ fmap f . fmap g

In the above interface, t represents a dummy tycon for which a
function fmap is defined that has the given signature and satisfies
the axioms.  fmap transforms any function into a function whose domain
and codomain are types produced by that constructor.  (Given that the
original function's domain and codomain are a and b, fmap produces a
function whose domain and codomain are the types (t a) and (t b).)
In this way, fmap 'adapts' general functions for use within the data
structure represented by the tycon.

E.g., the t can be the tycon of lists which, given a type x, produces
a list with element type x.  That t is made an instance of Functor by
trivially defining fmap to be the library function 'map' which, given
a function f, creates a function that transforms a list by applying f
to each of its elements.

A tycon for which fmap exists is often, informally, called a functor.
Strictly speaking, it implements a functor with codomain the tycon's
respective category.

Note that fmap only represents the arrow part of the functor.  The
object part is implicit.  It must also be stressed that satisfying
the axioms is not (and could not be) automatic – ensuring that they
are valid for a specific implementation of fmap is a programmer's
obligation!

Functors in J?
**************

The observed correspondence between category theory and Haskell can
be summarized in the following table.

category theory           Haskell
---------------------------------------------------------------------
category                  the universal category of types;
                          specific categories (families of datatypes)

category constructor      type constructor

object                    type

arrow                     function

composition of arrows     composition of functions

definition of functor     Functor interface and axioms
as concept

functor                   axioms-complying implementation of Functor
                          (associated with a specific tycon)

If we can build a similar table with J in the right column, we can
say that we have an idea what might be a J's version of functors in
general.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to