例如
let When true d = d
let foo = () |> When false
所以我有我不喜欢的副作用,因为它是错误的:MatchFailureException
我知道我在这里可以有很好的副作用:let foo = if false then ()
但是警告Incomplete pattern matches on this expression.
告诉我,我可以添加我需要的东西。我只是不知道如何或是否可能?否则为什么我什至可以使用值作为参数?
顺便说一句:我知道我会写When b d = if b then d else ()
,但问题更笼统。
在 haskell 中添加解释
let wh :: Bool -> IO () -> IO ()
wh True f = f
wh False f = return ()