Achim Schneider wrote: > ChrisK <[EMAIL PROTECTED]> wrote: > >> zeroNothing Nothing = Nothing >> zeroNothing (Just n) = >> if n == 0 then Nothing else (Just n) >> >> versus >> >> zeroNothing Nothing = Nothing >> zeroNothing x@(Just n) = >> if n == 0 then Nothing else x >> > versus > > zeroNothing Nothing = Nothing > zeroNothing x = > let (Just n) = x > in if n == 0 then Nothing else x > > so, @ is kind of like a let, just with its arguments flipped.
However, if x@(Just n) fails to match, the next clause is chosen, whereas the variable pattern x matches always. Thus, the last version works only because the other possible case (Nothing) has already been handled. IOW, in the second version of zeroNothing you may swap the order of patterns, but not in the third one. Cheers Ben _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
