[Haskell] insufficiently laziness@pattern -- more
counterintuitive stuff
Hal Daume III
hdaume at ISI.EDU
Tue Mar 30 09:07:41 EST 2004
A lot. If everything were irrefutable, then the following:
> mymap f (x:xs) = f x : xs
> mymap f [] = []
would never get to the second branch and would fail when it reached the
end of a list. so would it if you put the lines in the other, "more
natural," order, though perhaps it's less clear why.
A lot of things would break if this were changed. Refutable patterns are
definitely the norm, not the exception.
On Tue, 30 Mar 2004, S. Alexander Jacobson wrote:
> Thanks for the ~ syntax, but my question is really
> why you need it? What benefit do you get from
> "refutable patterns"?
>
> Alternatively, would anything break if a future
> Haskell just treated all patterns as irrefutable?
>
> -Alex-
>
> _________________________________________________________________
> S. Alexander Jacobson mailto:me at alexjacobson.com
> tel:917-770-6565 http://alexjacobson.com
>
>
> On Tue, 30 Mar 2004, Martin [ISO-8859-1] Sjögren wrote:
>
> > 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
> >
>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
--
Hal Daume III | hdaume at isi.edu
"Arrest this man, he talks in maths." | www.isi.edu/~hdaume
More information about the Haskell
mailing list