categories - Category Theory list
 help / color / mirror / Atom feed
From: "Carsten Führmann" <c.fuhrmann@bath.ac.uk>
To: Mike Stay <metaweta@gmail.com>
Subject: Re: additions
Date: Fri, 25 Dec 2009 09:18:47 +0100	[thread overview]
Message-ID: <E1NOGXD-0002xc-4N@mailserv.mta.ca> (raw)
In-Reply-To: <7f854b310912240825s39f195b2x2db16cc8f3a5cde7@mail.gmail.com>


Dear Mike,

 >> It might be worth noting that JavaScript is a functional language.
 >> (It has a lambda operator ("function"), closures, and can pass
 >> functions as parameters and return values.) However, because it has
 >> eager evaluation, the whole monad business does not apply, at least
 >> not
 >> in the way it applies to Haskell.
 >>
 >> In fact, JavaScript is probably the most widely used functional
 >> language
 >> on the planet.
 >
 > I think you're confusing the existence of first-class functions with
 > functional programming.  Functional programming avoids state and
 > mutable data. It emphasizes the application of functions, in contrast
 > to the imperative programming style, which emphasizes changes in
 > state.
 >
 > It's certainly possible to write functional programs in any of these
 > languages, but it takes a lot of conscious effort--in fact, I'd say
 > it's harder to write a functional program in JavaScript because of the
 > myriad of strange ways state changes occur.

I used the term "functional [programming] language" on purpose (as
opposed to "functional programming style"), because of your statement

 >> So there's not a lot of call for learning a functional programming
language either.

which I feel might be wrong. I meant that JavaScript is a functional
programming language in the same way in which ML/OCaml/F#, Lisp, and
Scheme are (just uglier, slower, and running in a sandbox called
"browser"). These are considered functional languages by many, and
their categorical semantics has been studied. (Well, the semantics of
idealized versions.)  JavaScript is just riddled with some syntactic
and semantic ugliness that makes it unattractive for formal study, but
that doesn't make it un-functional in principle.

 > I'm not sure what you mean by "the whole monad business does not
 > apply".  There are lots of monads, each doing something different.
 > There are several monadic parsers I know of in JavaScript, for
 > instance.  Here's a monad for making JavaScript be lazily evaluated
 >instead of eager:
 >  function e(x) { return function() { return x; } }
 >  function m(x, y) { return function () { return x()(y()); } }

Doesn't very fact that JavaScript allows you to write down the
delaying monad give away its functional-language nature? And doesn't
the existence of monadic parsers in JavaScript underpin that it might
be beneficial for real-life programmers to learn some functional
programming?

By "monad business" I meant using monads to introduce side effects to
lazy languages like Haskell, I could have been clearer there.

Categorically, your monad is of a different kind, as I shall now
sketch. (Just in case anyone is interested.)  First, we need to
observe that it is not straightforwardly a monad in the categorical
sense.  The reason is that the naturality square of the "unit" e does
not commute.  Considering that underlying functor T of the
monad-in-spe sends a morphism f to

T f = lambda g.lambda().f(g())

the naturality square would be

e \circ f == (lambda g.lambda (). f(g())) \circ e

which fails iff the f has a side effect (in the widest sense, which
includes going into an infinite loop): that effect would get invoked
on the equation's left side but not on the right.  However, your code
*does* represent a monad on the subcategory of (denotations of)
effect-free (and terminating) programs. Categorically, (T, m, e)
corresponds to an attempt to define a strong monad on an *unspecified*
subcategory of the symmetric premonoidal category (not CCC!)  that
models your eager language (long story...). Fortunately, such a
categories exist: e.g.  the maximum one is given by all morphisms
w.r.t. which your unit-in-spe is natural, but again that's a long
story.  At any rate, from a categorical and conceptional point of view
the delaying "monad" on an eager language differs from Haskell-style
monads.


Happy holidays,
    Carsten


http://www.cs.bath.ac.uk/~cf/


[For admin and other information see: http://www.mta.ca/~cat-dist/ ]


  parent reply	other threads:[~2009-12-25  8:18 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-17 23:30 A well kept secret? peasthope
2009-12-18  4:09 ` John Baez
2009-12-18 22:25   ` Ellis D. Cooper
2009-12-19 17:45     ` Ronnie Brown
2009-12-19 22:16     ` John Baez
2009-12-20 22:52       ` Greg Meredith
2009-12-21 15:46       ` Zinovy Diskin
2009-12-22 16:59         ` zoran skoda
2009-12-23  1:53       ` Tom Leinster
2009-12-23 14:15         ` Colin McLarty
2009-12-23 19:10       ` CatLab Joyal, André
2009-12-20 21:50     ` A well kept secret? jim stasheff
     [not found]     ` <d4da910b0912220859q3858b68am4e58749f21ce839d@mail.gmail.com>
2009-12-23  4:31       ` Zinovy Diskin
2009-12-23 14:35         ` Ronnie Brown
     [not found]     ` <4B322ACA.50202@btinternet.com>
2009-12-25 20:06       ` Zinovy Diskin
2009-12-20 17:50   ` Joyal, André
     [not found]     ` <B3C24EA955FF0C4EA14658997CD3E25E2159B6AA@CAHIER.gst.uqam.ca>
2009-12-21  8:43       ` additions Joyal, André
2009-12-21 14:16         ` additions Bob Coecke
2009-12-22  2:24           ` additions Joyal, André
2009-12-23 20:51             ` additions Thorsten Altenkirch
2009-12-24 23:55             ` additions Dusko Pavlovic
2009-12-26  2:14             ` additions Peter Selinger
     [not found]           ` <B3C24EA955FF0C4EA14658997CD3E25E370F5626@CAHIER.gst.uqam.ca>
     [not found]             ` <B3C24EA955FF0C4EA14658997CD3E25E370F5636@CAHIER.gst.uqam.ca>
     [not found]               ` <B3C24EA955FF0C4EA14658997CD3E25E370F5638@CAHIER.gst.uqam.ca>
2009-12-28 17:54                 ` quantum information and foundation Joyal, André
2009-12-29 12:13                   ` Urs Schreiber
2009-12-29 15:55                   ` zoran skoda
2009-12-22  0:39         ` additions Mike Stay
2009-12-23 11:19           ` additions Steve Vickers
2009-12-23 18:06             ` additions Mike Stay
2009-12-24 13:12               ` additions Carsten Führmann
2009-12-24 19:23               ` additions Dusko Pavlovic
2009-12-23 19:06             ` additions Thorsten Altenkirch
     [not found]         ` <Pine.LNX.4.64.0912211413340.15997@msr03.math.mcgill.ca>
     [not found]           ` <B3C24EA955FF0C4EA14658997CD3E25E2159B6B3@CAHIER.gst.uqam.ca>
2009-12-23 17:08             ` RE : categories: additions Joyal, André
2009-12-21 19:20   ` additions Michael Barr
2009-12-27 23:14   ` quantum information and foundation Dusko Pavlovic
     [not found]   ` <Pine.GSO.4.64.0912272037140.28761@merc3.comlab>
2009-12-28 16:38     ` Bob Coecke
     [not found]   ` <Pine.GSO.4.64.0912281630040.29390@merc4.comlab>
2009-12-28 18:17     ` Bob Coecke
2009-12-18 10:48 ` A well kept secret? KCHM
2009-12-19 20:55   ` Vaughan Pratt
2009-12-22 12:21 ` additions Mark Weber
2009-12-23  0:05   ` additions Scott Morrison
2009-12-23 14:13     ` additions Mark Weber
     [not found] ` <B3C24EA955FF0C4EA14658997CD3E25E2159B6B8@CAHIER.gst.uqam.ca>
2009-12-23 21:04   ` CatLab Urs Schreiber
     [not found] ` <4B3368C1.3000800@bath.ac.uk>
2009-12-24 16:25   ` additions Mike Stay
2009-12-26  0:03     ` additions Toby Bartels
     [not found]   ` <7f854b310912240825s39f195b2x2db16cc8f3a5cde7@mail.gmail.com>
2009-12-25  8:18     ` Carsten Führmann [this message]
     [not found] ` <4B347567.9070603@bath.ac.uk>
2009-12-29 23:17   ` additions Mike Stay
2009-12-30 21:00     ` additions Greg Meredith
2009-12-22  1:43 additions Fred E.J. Linton
2009-12-23  1:38 additions Fred E.J. Linton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1NOGXD-0002xc-4N@mailserv.mta.ca \
    --to=c.fuhrmann@bath.ac.uk \
    --cc=metaweta@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).