よりエレガントに表現できると思われるパターンに出会いました。
私は2つの関数f1,f2 :: Int -> Int
(それらの実装は関係ありません)と、次のことを行う aprocess :: Int -> Int
を持っています:
- と異なる場合
f1 x
は、プロセスを繰り返しますx1
x
x1
- それ以外の場合、と異なる場合
f2 x
は、プロセスを繰り返しますx2
x
x2
- 最後に、プロセスを停止して戻ります
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
どのパターンが重複しているか、よりエレガントに実装する方法について、誰かが光を当てることができますか?