LoginSignup
1
0

More than 5 years have passed since last update.

do記法でパターンマッチにしくじるとfailが使われる

Last updated at Posted at 2012-12-26

以下のhogeとhoge'は同じかと思ってたけど、別物。

hoge :: [Int]
hoge = do
  Just x <- [Just 3, Just 2, Nothing, Just 4]
  return x

hoge' :: [Int]
hoge' = [Just 3, Just 2, Nothing, Just 4] >>= (\ (Just x) -> return x)

http://www.haskell.org/onlinereport/exps.html によると、do記法の書き換えは以下なので。

do {p <- e; stmts}  =   let ok p = do {stmts}
                            ok _ = fail "..."
                        in e >>= ok

動きから予想はしてたけど、やっぱ fail かあ。。。

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0