Haskell常数与模式匹配
如何在Haskell中定义宏常量?特别是,我希望下面的代码段在不重叠第二个模式匹配的情况下运行Haskell常数与模式匹配,haskell,pattern-matching,pattern-synonyms,Haskell,Pattern Matching,Pattern Synonyms,如何在Haskell中定义宏常量?特别是,我希望下面的代码段在不重叠第二个模式匹配的情况下运行 someconstant :: Int someconstant = 3 f :: Int -> IO () f someconstant = putStrLn "Arg is 3" f _ = putStrLn "Arg is not 3" 您可以定义一个: 但也要考虑在自定义变体类型上匹配不是更好,而不是 int >代码> .< /p>你应该澄清你不是在寻找一个守卫
someconstant :: Int
someconstant = 3
f :: Int -> IO ()
f someconstant = putStrLn "Arg is 3"
f _ = putStrLn "Arg is not 3"
您可以定义一个:
但也要考虑在自定义变体类型上匹配不是更好,而不是<代码> int >代码> .< /p>你应该澄清你不是在寻找一个守卫<代码> fx*x==SoMeStista= PutStrun“是3”< />代码,但是你真的想要一个模式。(对吗?)
{-# LANGUAGE PatternSynonyms #-}
pattern SomeConstant :: Int
pattern SomeConstant = 3
f :: Int -> IO ()
f SomeConstant = putStrLn "Arg is 3"
f _ = putStrLn "Arg is not 3"