[Haskell] insufficiently laziness@pattern -- more counterintuitive stuff

MartinSjögren md9ms at mdstud.chalmers.se
Tue Mar 30 17:48:35 EST 2004


tis 2004-03-30 klockan 17.30 skrev S. Alexander Jacobson:
> I would assume that this function:
> 
>   foo list@(h:t) = list
> 
> is equivalent to
> 
>   foo list = list
>      where (h:t)=list
> 
> But passing [] to the first generates an error
> even though h and t are never used!  Passing [] to
> the second works just fine.

You can write this as

> foo' list@(~(h:t)) = list

foo' [] will evaluate to []. The H98 report calls it an "irrefutable
pattern", IIRC.


Regards,
Martin



More information about the Haskell mailing list