[Haskell-beginners] homogeneous value list

Thomas Davie tom.davie at gmail.com
Fri Mar 12 09:28:29 EST 2010

On 12 Mar 2010, at 14:25, Salil Wadnerkar wrote:

> On Fri, Mar 12, 2010 at 10:21 PM, Ozgur Akgun <ozgurakgun at gmail.com> wrote:
>> Another boring variant from me then.
>> isHomogeneous xs = all (first==) xs
>>     where first = head xs
> Shouldn't
> head xs
> give an exception on an empty list?

An error, and only if it's evaluated.  Lazy evaluation means it's not evaluated here.

Of course another non-strict algorithm *might* evaluate head xs here, so this version won't work in all possible Haskell implementations, only the current ones which use lazy evaluation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100312/485afe6b/attachment.html

More information about the Beginners mailing list