Is there a relationship between visitor pattern and DeMorgan's Law? Visitor Pattern enables mimicking sum types with product types. Where does the &quot;sum&quot;-iness come from?
For example, in OCaml one could define type my_bool = True | False
Or encode with visitor pattern:
type 'a bool_visitor = {
  case_true: unit -&gt; 'a;
  case_false: unit -&gt; 'a;
}

let t visitor = visitor.case_true () 
let f visitor = visitor.case_false ()
  
let visitor = {
  case_true = (fun () -&gt; &quot;true&quot;);
  case_false = (fun () -&gt; &quot;true&quot;);
} 
  
  
let () = print_endline (t visitor) (* prints &quot;true&quot; *)

What's the best way of explaining the sum-type-to-visitor-pattern transformation? Is it:

Of course + and * are interdefinable, what did I expect?
Or is it that the left side of -&gt; is the &quot;negative&quot; position and that this leads to a DeMorgan-law-like flip of sum and product?

I also wonder if this question is related to how one can use universally-quantified types to mimic existential types.
The best way to explain it is
$$\mathsf{Bool} \to C \cong C \times C,$$
which is a special case of
$$(A + B) \to C \cong (A \to C) \times (B \to C).$$
Read the above as follows: as sum is equivalent to a pair of visitors.
(By the way, this is not the de Morgan law. It does not have a name, as far as I know. It's a general consequence of the definition of the concepts involved.)