[Haskell-cafe] Why isn't pattern matching lazy by default?

C.M.Brown cmb21 at kent.ac.uk
Wed Sep 19 07:57:37 EDT 2007


>
> f ~(x:xs) = x + 2
> f ~[] = 42
>
> Then f [] would give a complie error:
>  Irrefutable pattern failed for pattern (x : xs)

Sorry, that should be *runtime* error!

Chris.



>
> Hope that gives some insight.
> Chris.
>
>
> >
> > Oh well, the way it is now is also easy to get used to, one just has to
> > know how it works (just like M-theory ;-) )
> >
> > Cheers,
> > Peter
> >
> >
> > Neil Mitchell wrote:
> > > Hi
> > >
> > >
> > >>>  Now why isn't pattern matching lazy by default?  This seems odd for a
> > >>> newbie since everything else is lazy by default.
> > >>>
> > >
> > > f ~(x:xs) = rhs
> > > f ~[]     = rhs'
> > >
> > > Now guess what f [] does...
> > >
> > > If you use a where binding then pattern matching is lazy.
> > >
> > > Thanks
> > >
> > > Neil
> > >
> > >
> > >
> >
> >
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list