[Haskell-cafe] Laziness question
Nicolas Pouillard
nicolas.pouillard at gmail.com
Sun Aug 1 04:32:46 EDT 2010
On Sat, 31 Jul 2010 17:30:54 -0400, Brandon S Allbery KF8NH <allbery at ece.cmu.edu> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 7/31/10 16:58 , wren ng thornton wrote:
> > Brandon S Allbery KF8NH wrote:
> >> michael rice wrote:
> >>> Are you saying:
> >>>
> >>> [ head x ] -> [ *thunk* ] and length [ *thunk* ] -> 1, independent of
> >>> what *thunk* is, even head [], i.e., *thunk* never needs be evaluated?
> >>
> >> Exactly. (I was being cagey because the first response was cagey, possibly
> >> suspecting a homework question although it seems like an odd time for it.)
> >>
> >> length not only does not look inside of the thunk, it *can't* look inside
> >> it; all it knows is that it has a list, it specifically does *not* know what
> >> that list can hold. So the only thing it can do is count the number of
> >> "unknown somethings" in the list.
> >
> > Not entirely true:
> >
> > stupidlyStrictLength :: [a] -> Integer
> > stupidlyStrictLength [] = 0
> > stupidlyStrictLength (x:xs) = x `seq` 1 + stupidlyStrictLength xs
>
> Given all the messes seq makes ("hey, go behind the compiler's back and
> touch this arbitrary value of arbitrary type"), I generally consider it to
> be unsafeSeq :)
I would deeply in favor of renaming seq to unsafeSeq, and introduce a
type class to reintroduce seq in a disciplined way.
--
Nicolas Pouillard
http://nicolaspouillard.fr
More information about the Haskell-Cafe
mailing list