Re:The visitor pattern is essentially the same thing as Chur...
by h_anna_h on Thursday February 04, 2021 @03:38PM
(#26029520)
What is the point of doing forall T but not forall A and B?
[ Parent
| on HN ]
Re:The visitor pattern is essentially the same thing as Chur...
by Twisol on Thursday February 04, 2021 @04:25PM
(#26029985)
A and B are free to be chosen by a producer of the generic Sum type. However, T can be chosen "late", by a consumer of Sum; a value of type Sum A B must work for any T you decide to use down the line.
If it helps, the equivalent Java signature is:
interface Sum<A, B> {
<T> T visit(Function<A, T> onA, Function<B, T> onB);
}
Hopefully this makes it more clear that A and B are fixed when you receive a value of type Sum A B, but you get to pick a T when consuming that value.