News for hackers. Stuff that matters.
Re:The visitor pattern is essentially the same thing as Chur... by johndoe42377 on Thursday February 04, 2021 @08:30AM (#26025133)
Obviously, not. Not even apples versus oranges. Church encoding shows you that "all you need is lambda", which is the same to say all you need is a membrane in biology.

Even further, Lambda calculus shows you that function creation and application are necessary and sufficient for everything, with obvious parallels to biology (enzymes are just proteins).

Visitor pattern is just some wired wrapping to satisfy a rigid type system, which composition of Traits or typeclasses would solve. One just pass a function which knows the structure.

Re:The visitor pattern is essentially the same thing as Chur... by Twisol on Thursday February 04, 2021 @08:44AM (#26025229)
> Obviously, not. Not even apples versus oranges.

Formally, `A + B` is isomorphic to `forall T. (A -> T, B -> T) -> T`, where the inner `(A -> T, B -> T)` is the type of a visitor.

    a + b
    -- CPS transform
    = forall t. ((a + b) -> t) -> t
    -- distribute -> over +
    = forall t. (a -> t, b -> t) -> t
    -- if you want to drop even the product, distribute -> over *
    -- but this loses you the ability to name a separable Visitor
    = forall t. (a -> t) -> (b -> t) -> t

    type Visitor a b t = (a -> t, b -> t)
    type Sum a b = forall t. Visitor a b t -> t

    iso :: Sum a b -> (a + b)
    iso s = s (Left, Right)
    
    osi :: (a + b) -> Sum a b
    osi (Left a) = \(onA, onB) -> onA a
    osi (Right b) = \(onA, onB) -> onB b
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?
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.
Re:The visitor pattern is essentially the same thing as Chur... by h_anna_h on Thursday February 04, 2021 @06:48PM (#26031178)
Thanks
Re:The visitor pattern is essentially the same thing as Chur... by johndoe42377 on Thursday February 04, 2021 @10:44AM (#26026294)
I really don't know how to respond to this sectarian bullshit.

Three is literally nothing in the ability to create another abstraction by finding an isomorphism, which is just a pair of functions.

Re:The visitor pattern is essentially the same thing as Chur... by Gabriel439 on Thursday February 04, 2021 @11:26AM (#26026822)
You're right that there is no benefit in creating another abstraction, but the point of the post is sometimes the language doesn't have support for the original abstraction (e.g. sum types), so in some cases the other abstraction (e.g. visitor pattern or Church encoding) is the only available abstraction.
Re:The visitor pattern is essentially the same thing as Chur... by johndoe42377 on Sunday February 07, 2021 @01:20AM (#26053095)
Look, I never tried to be offensive or even bully. But I care about the principle of calling things by its proper names and precise language usage. I am describing things exactly how I see them.

And I have reasons to do so. Like so many others I have traveled that road, from Haskell basics up to the latest writings and courses of that self-propelled category theory expert - Bartosz, for whom I have great respect.

However, at the end of the journey I came to different conclusions, that the whole subfield is nothing but a sect (the definition is a consensus based group of eager supporters) and the whole set of nested abstractions is empty of meaning, except in producing deeper and deeper nested abstractions. I cold provide analogies with Eastern religious sects, which I have studied too, where abstract things are described in minute details, and the merit is in the knowledge of these minute details, but I won't. It will only complicate this discussion.

So I don't see any meaning, and I see socially constructed interested, identical to esoteric teachings, which is even better definition of what Bartosz and others are doing.

Let's say it is Hegel all over again.

Re:The visitor pattern is essentially the same thing as Chur... by johndoe42377 on Thursday February 04, 2021 @11:09AM (#26026614)
Oh, I forgot to mention, that "enzymes are proteins" is isomorphic (lol) to "procedures are list structures" (or "code is data") which explains the miracle of Lisp and it's macros and connects Lisp to life itself, and justifies why MIT folks ware so fascinated with it.