sebastian.sylvan at gmail.com
Mon Mar 20 11:26:58 EST 2006
On 3/20/06, Manuel M T Chakravarty <chak at cse.unsw.edu.au> wrote:
> Sebastian Sylvan:
> > 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.
Ah yes, I get it now.
What I wrote was more related to Bang patterns then (so it's a bit
OT). The more I think about bang patterns, though, the more it seems
reasonable that "f !(a,b)" shouldn't be equivalent to "f (a,b)". If
one thinks about ! as removing one "layer" of laziness (e.g. !xs will
force a list, but not its elements) then it should make sense that
applying ! to a pattern where one (or more) "layer" of laziness has
already been removed (via pattern matching) would result in forcing
the next "layer" (e.g. ![a,b] would evaluate a and b, since the list
itself has already been forced via pattern matching).
It makes sense to me to at least. More sense than having ! do nothing
in circumstances like the above, anyway.
More information about the Haskell-prime