あなたが望むのは、非常に大まかに言えば、アドホックなポリモーフィズムまたはオーバーロードです。それは OCaml では不可能であり、さらに重要なことに、OCaml で使用したくありません。
複数の型を返す関数が必要な場合は、これらの型を表現できる新しい「合計」型を定義する必要があります。ここでは、ブール値またはタプルを返したいので、「ブール値」を意味する新しい型またはタプル」。OCaml では、次のような型を定義します。
type ('a, 'b) t = Bool of bool
| Tuple of 'a * 'b
この新しい合計型を使用すると、コードは次のようになります。
type ('a, 'b) t =
| Bool of bool
| Tuple of 'a * 'b
let match_element (a, b) =
if a = b then Bool true
else if dont_care a || dont_care b then Bool true
else if is_variable a then Tuple (a, b)
else if is_variable b then Tuple (b, a)
else Bool false;;
ここで 2 つのパラメーター ('a と 'b) を持つ型 t は、目的には一般的すぎる可能性がありますが、コンテキストから何をしたいのか推測できません。次のような、あなたの意図に合ったより良い型定義があるかもしれません:
type element = ... (* Not clear what it is from the context *)
type t =
| I_do_not_care (* Bool true in the above definition *)
| I_do_care_something (* Bool false in the above definition *)
| Variable_and_something of element * element (* was Tuple *)