如何在Haskell中定义宏常量?特别是,我希望以下代码片段可以运行而不需要第二个模式匹配重叠。
someconstant :: Int
someconstant = 3
f :: Int -> IO ()
f someconstant = putStrLn "Arg is 3"
f _ = putStrLn "Arg is not 3"
如何在Haskell中定义宏常量?特别是,我希望以下代码片段可以运行而不需要第二个模式匹配重叠。
someconstant :: Int
someconstant = 3
f :: Int -> IO ()
f someconstant = putStrLn "Arg is 3"
f _ = putStrLn "Arg is not 3"
f x | x==someconstant = putStrLn "is 3"
,而是您真正想要的是一个模式。 (对吗?) - chi