Haskellでマクロ定数を定義するにはどうすればよいですか? 特に、次のスニペットは、2 番目のパターン マッチが重ならないように実行してほしいと思います。
someconstant :: Int
someconstant = 3
f :: Int -> IO ()
f someconstant = putStrLn "Arg is 3"
f _ = putStrLn "Arg is not 3"
Haskellでマクロ定数を定義するにはどうすればよいですか? 特に、次のスニペットは、2 番目のパターン マッチが重ならないように実行してほしいと思います。
someconstant :: Int
someconstant = 3
f :: Int -> IO ()
f someconstant = putStrLn "Arg is 3"
f _ = putStrLn "Arg is not 3"
パターン シノニムを定義できます。
{-# LANGUAGE PatternSynonyms #-}
pattern SomeConstant :: Int
pattern SomeConstant = 3
f :: Int -> IO ()
f SomeConstant = putStrLn "Arg is 3"
f _ = putStrLn "Arg is not 3"
ただし、Int
.