caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@ozemail.com.au>
To: Chris Hecker <checker@d6.com>
Cc: Xavier Leroy <xavier.leroy@inria.fr>,
	Francois Pottier <francois.pottier@inria.fr>,
	caml-list@inria.fr
Subject: Re: [Caml-list] Re: generic programming
Date: Sat, 06 Jul 2002 05:31:12 +1000	[thread overview]
Message-ID: <3D25F400.6090703@ozemail.com.au> (raw)
In-Reply-To: <4.3.2.7.2.20020705024112.038909f0@mail.d6.com>

Chris Hecker wrote:

>
> Both of these are examples of "push versus pull" interfaces, and pull 
> just seems to work better.  Having data pushed at you means you often 
> end up buffering it on your end to manage your flow control anyway 
> unless you're just doing some trivial processing. 

This was once explained to me really well, I can't hope to give as good 
an explanation as I was given,
but I'll try: the reason 'pull' is better is that the natural place to 
put your state data is
'on the stack' and the most important case of this data is the program 
counter.

Put another way, your location in the code is the best way to encode the 
configuration
of your state data, which has something to do with the naturalness of 
block structured
programming: when you are 'here' in the code, 'these' variables are visible
and contain the state.

> I'm not saying that callback/push interfaces are always bad, 

What Francois Pottier said is correct, IMHO: callbacks are best in 
simple cases,
in particular, when there is NO state, using them clearly makes the 
simple structure
of your code evident in the syntax.

Callbacks are *also* probably best when the problem is extremely
complex.

But 'pull' interfaces shine when there is a natural heirarchical
decomposition which can be readily represented by putting
all your state data on the machine stack, and encoding
the 'variant tag' of the union of all stack states in the
natural place -- the program counter.

So: when you don't need state data, the stack doesn't help,
you might as well use a callback. And when the problem
is really complex, you might as well put all your data
into an object, and drive the system as a state machine:
this is better than mixing up the explicit and implicit
state in an arbitrary way (some on the stack, some
in a state object ..) In between, there is a large class
of tree structured problems that admit a clean solution using
subroutines and local variables.

Classic example: recursive descent parser.

Classic counter example: Earley parser (needs frames threaded
in two distinct ways, to allow one to go back and try again
after success as well as failure).

heh. It is interesting that Ocaml experts are arguing
for functional iterators -- which in fact amount
to 'goto' programming, whilst the 'pull' interface
is the essence of functional decomposition :-)
The power and utility of the machine stack is hard
to deny -- it is important enough that hardward provides it :-)

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2002-07-05 19:31 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-03  2:49 [Caml-list] " Oleg
2002-07-03  8:37 ` [Caml-list] " Ketanu
2002-07-03 17:29   ` Chris Hecker
2002-07-03 20:07     ` Oleg
2002-07-03 20:34       ` Alessandro Baretta
2002-07-04 15:33         ` John Max Skaller
     [not found]           ` <3D249B27.5080807@baretta.com>
     [not found]             ` <3D25D27B.2020005@ozemail.com.au>
2002-07-07 20:42               ` Alessandro Baretta
2002-07-08  0:59                 ` John Max Skaller
2002-07-08  7:29                   ` Alessandro Baretta
2002-10-15  0:10         ` Eray Ozkural
2002-07-03 21:55     ` Peter Wood
2002-07-04  2:02       ` james woodyatt
2002-07-04 15:18     ` John Max Skaller
2002-07-05  8:42       ` Francois Pottier
2002-07-05  9:25         ` Xavier Leroy
2002-07-05  9:57           ` Chris Hecker
2002-07-05 13:54             ` Xavier Leroy
2002-07-05 17:59               ` Chris Hecker
2002-07-05 20:31                 ` John Max Skaller
2002-07-05 19:33               ` John Max Skaller
2002-07-05 19:31             ` John Max Skaller [this message]
2002-07-05  8:33     ` Francois Pottier
2002-07-05 23:05       ` Dave Berry
2002-07-08  9:54         ` Francois Pottier
2002-07-08 15:49           ` John Max Skaller
2002-08-02 14:49         ` [Caml-list] Streams Diego Olivier Fernandez Pons
2002-08-02 15:29           ` Alain Frisch
2002-08-03 14:19             ` Diego Olivier Fernandez Pons
2002-07-03  8:42 ` [Caml-list] generic programming Johan Baltié
     [not found]   ` <002301c22270$fb4ca160$2be213c3@youngkouzdra>
     [not found]     ` <20020703092753.M39371@wanadoo.fr>
2002-07-05 10:38       ` Anton Moscal
2002-07-03  9:10 ` Jun P.FURUSE

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=3D25F400.6090703@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --cc=caml-list@inria.fr \
    --cc=checker@d6.com \
    --cc=francois.pottier@inria.fr \
    --cc=xavier.leroy@inria.fr \
    /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).