このコードを検討してください:
case action1 of
Right a -> a
Left (Failure1 a) -> a
Left (Failure2 a) ->
case action2 a of
Right a -> a
_ -> error "Unexpected failure"
_ -> error "Unexpected failure"
2 回繰り返す必要があることがわかります。ケースRight
とerror
ケースです。
これを最適化するにはどうすればよいですか?それはまったく可能ですか?