[Haskell-cafe] Re: If wishes were horses... (was: Re: definition of sum)

Johannes Waldmann waldmann at imn.htwk-leipzig.de
Fri Mar 12 04:29:37 EST 2010


> > Note that foldl' has a ' to indicate that it's not the same as foldl
> > exactly.  I would propose that sum' exist as well as sum, and that sum be
> > lazy.

Well, meaningful identifier names is nice, but I think
here we have a case of the code smell "type info embedded in the name".
Strictness of a function should be expressed in the function's type instead.
But that seems impossible with Haskell at the moment.
(At best, we can express strictness of constructors?)
Hence we have "underspecified" behaviour:

Prelude Data.List> :t foldl'
foldl' :: (a -> b -> a) -> a -> [b] -> a

Prelude Data.List> :t foldl
foldl :: (a -> b -> a) -> a -> [b] -> a

and need to resort to the awkward workaround via naming conventions.

Of course Haskell implementations do have some kind of strictness
information (e.g., in ghc interface files), so it's not impossible
to define some kind of annotation system.

Although I did not check what the compiler's strictness info is 
for foldl and fold' - and what was actually needed (at the source level).
The current textual definition (Data.List API docs: "foldl' = a 
strict version of foldl") is not too precise, either.

Well, I guess there's a huge design space. But it's a huge problem
(describing/controlling the behaviour of lazy programs).

Best - J.W.




More information about the Haskell-Cafe mailing list