3

Haskellでマクロ定数を定義するにはどうすればよいですか? 特に、次のスニペットは、2 番目のパターン マッチが重ならないように実行してほしいと思います。

someconstant :: Int
someconstant = 3

f :: Int -> IO ()
f someconstant = putStrLn "Arg is 3"
f _            = putStrLn "Arg is not 3"
4

1 に答える 1

13

パターン シノニムを定義できます。

{-# LANGUAGE PatternSynonyms #-}

pattern SomeConstant :: Int
pattern SomeConstant = 3

f :: Int -> IO ()
f SomeConstant = putStrLn "Arg is 3"
f _            = putStrLn "Arg is not 3"

ただし、Int.

于 2016-02-15T19:20:58.743 に答える