#module MonadTest where
sheep :: Num a => a -> Maybe a
sheep 0 = Nothing
sheep x = Just x
test :: Num a => a -> Maybe a
test x = return x >>= sheep >>= sheep >>= sheep >>= sheep
#で、 Nothing なら Nothing に短絡評価されるよう GHC が最適化してくれるよね、という話をしてました。
#ghc -c -O2 MonadTest.hs -ddump-simpl
#MonadTest.test =
\ (@ a_ah3) ($dNum_ahn :: GHC.Num.Num a_ah3) ->
let {
sheep2_sjm [ALWAYS Just L] :: a_ah3 -> Data.Maybe.Maybe a_ah3
LclId
[Str: DmdType]
sheep2_sjm = MonadTest.sheep @ a_ah3 $dNum_ahn } in
\ (x_adj :: a_ah3) ->
case sheep2_sjm x_adj of _ {
Data.Maybe.Nothing -> Data.Maybe.Nothing @ a_ah3;
Data.Maybe.Just x1_Xjl ->
case sheep2_sjm x1_Xjl of _ {
Data.Maybe.Nothing -> Data.Maybe.Nothing @ a_ah3;
Data.Maybe.Just x2_XjD ->
case sheep2_sjm x2_XjD of _ {
Data.Maybe.Nothing -> Data.Maybe.Nothing @ a_ah3;
Data.Maybe.Just x3_XjC -> sheep2_sjm x3_XjC
}
}
}
##今日のRWH読書会の懇親会で出た話題の「togetter 派遣PG時代の思い出」はこちらです。
#