[Haskell-cafe] a monad for secret information
bulat.ziganshin at gmail.com
Wed Oct 11 02:43:40 EDT 2006
Wednesday, October 11, 2006, 4:47:59 AM, you wrote:
> Why does this works? "Yet Another Haskell Tutorial" teaches that
> pattern matching occurs at one stage and guard processing at other,
> and that there's no back (page 94).
something is definitely wrong - either book or your understanding. it's
very widely used feature, i just took a quick scan of Hugs Prelude and
found a lot of its uses:
(!!) :: [a] -> Int -> a
xs !! n | n<0 = error "Prelude.!!: negative index"
 !! _ = error "Prelude.!!: index too large"
(x:_) !! 0 = x
(_:xs) !! n = xs !! (n-1)
lexmatch (x:xs) (y:ys) | x == y = lexmatch xs ys
lexmatch xs ys = (xs,ys)
showLitChar c | c > '\DEL' = showChar '\\' .
protectEsc isDigit (shows (fromEnum c))
showLitChar '\DEL' = showString "\\DEL"
x ^ 0 = 1
x ^ n | n > 0 = ....
_ ^ _ = error "Prelude.^: negative exponent"
i don't even say that i use this feature every day :)
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe