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

Felipe Almeida Lessa felipe.lessa at gmail.com
Wed Sep 19 18:16:18 EDT 2007


On 9/19/07, C.M.Brown <cmb21 at kent.ac.uk> wrote:
> > f x = let
> >           g (Just x) = x
> >           g Nothing = error "Nothing"
> >        in g x
> >
>
> That's interesting, thanks!

FYI, you may also use guards, even if you don't have a parameter. For
example, you may turn

f x = let k = if null x then 10 else head x
      in froobar $ quox k

into

f x = let k | null x    = 10
            | otherwise = head x
      in froobar $ quox k

Okay, this example is ugly, however it serves the purpose of
illustrating the idea =).

-- 
Felipe.


More information about the Haskell-Cafe mailing list