Manuel M T Chakravarty
chak at cse.unsw.edu.au
Mon Mar 20 11:00:19 EST 2006
> On 3/19/06, Manuel M T Chakravarty <chak at cse.unsw.edu.au> wrote:
> > Loosely related to Ticket #76 (Bang Patterns) is the question of whether
> > we want the language to include strict tuples. It is related to bang
> > patterns, because its sole motivation is to simplify enforcing
> > strictness for some computations. Its about empowering the programmer
> > to choose between laziness and strictness where they deem that necessary
> > without forcing them to completely re-arrange sub-expressions (as seq
> > does).
> > So what are strict tupples? If a lazy pair is defined in pseudo code as
> > data (a, b) = (a, b)
> > a strict pair would be defined as
> > data (!a, b!) = ( !a, !b )
> > Ie, a strict tuple is enclosed by bang parenthesis (! ... !). The use
> > of the ! on the rhs are just the already standard strict data type
> > fields.
> Maybe I've missed something here. But is there really any reasonable
> usage cases for something like:
> f !(a,b) = a + b
> in the current bang patterns proposal?
> I mean, would anyone really ever want an explicitly strict (i.e. using
> extra syntax) tuple with lazy elements?
> Couldn't the syntax for strict tuples be just what I wrote above
> (instead of adding weird-looking exclamation parenthesis).
> I'm pretty sure that most programmers who would write "f !(a,b) = ..."
> would expect the tuple's elements to be forced (they wouldn't expect
> it to do nothing, at least).. In fact !(x:xs) should mean (intuitively
> to me, at least) "force x, and xs", meaning that the element x is
> forced, and the list xs is forced (but not the elements of the xs).
> Couldn't this be generalised? A pattern match on any constructor with
> a bang in front of it will force all the parts of the constructor
> (with seq)?
The point about strict tuples is not that the components are forced on
pattern matching (that's indeed what bang patterns are for). The point
about strict tuples is that the components are forced *before* the tuple
is *constructed*. It's really exactly the same as with strict fields in
data type declarations today. So, yes, I can just define my own
data MyStrictPair a b = MyStrictPair !a !b
and use that. My point is simply that strict tuples are a particularly
useful form of strict data types, so
* they should be pre-defined in the Prelude and
* they should inherit the special syntax of tuples.
So, this is not so much a language feature as a library issue.
More information about the Haskell-prime