よりエレガントに表現できると思われるパターンに出会いました。
私は2つの関数f1,f2 :: Int -> Int(それらの実装は関係ありません)と、次のことを行う aprocess :: Int -> Intを持っています:
- と異なる場合
f1 xは、プロセスを繰り返しますx1xx1 - それ以外の場合、と異なる場合
f2 xは、プロセスを繰り返しますx2xx2 - 最後に、プロセスを停止して戻ります
x
私のcase ... of実装は次のとおりです。
f1 :: Int -> Int
f1 = undefined
f2 :: Int -> Int
f2 = undefined
process :: Int -> Int
process x =
case f1 x of
x ->
case f2 x of
x -> x
x' -> process x'
x' -> process x'
次の警告が生成されます。
so.hs:13:17: warning: [-Woverlapping-patterns]
Pattern match is redundant
In a case alternative: x' -> ...
|
13 | x' -> process x'
| ^^^^^^^^^^^^^^^^
so.hs:14:9: warning: [-Woverlapping-patterns]
Pattern match is redundant
In a case alternative: x' -> ...
|
14 | x' -> process x'
| ^^^^^^^^^^^^^^^^
processどのパターンが重複しているか、よりエレガントに実装する方法について、誰かが光を当てることができますか?