« first day (4398 days earlier)      last day (742 days later) » 
00:00 - 18:0018:00 - 00:00

18:00
Actually yes
But it should still use Rust enums
Not unions
Because any time you're using a union you still have an enum structure somewhere
Even if it's very indirectly
And IMO it makes way more sense to put the data in the enum instead of having them loosely related
@RydwolfPrograms as in like under the hood?
No, in your code
How else do you know what the type is
Even when you provide it to a function knowing it's a String, sure the function knows it's a String, but how does the caller know?
It has to store that somewhere
(and if your sum types work like that, then yeah, you also have to store it under the hood, but I'm assuming you do that anyway)
By partly decoupling the thing that determines the union's type from the union itself, you just introduce tons of opportunities for bugs
Rust's method might be very slightly more verbose, but it's good verbosity
(Verbosity that actually makes the code's possible actions clearer and common bugs impossible, rather than just adding clutter)
@RydwolfPrograms no the sum type exists only in the mind of the compiler
lua is dynamic, so it takes care of that for me
?
I'm talking about the code
Not the compiler
How does your code know if it's a String or an Int or an Expr
by casting or matching
18:07
Wdym by casting. Doesn't that require knowing what to cast to?
And if you're matching, how's that any different from a Rust-style enum? It's just less powerful since you can't have multiple things with the same type (e.g., an int used for a time vs. an int used for a full datetime)
what i meant was flow typing
@RydwolfPrograms thats my point
sum types can pretty much perfectly simulate rust enums
No they can't
Not without tons of annoying clutter
E.g., if you want to use a struct as one of the options, or have multiple options with the same type signature
i dont see how tons
i.e. in a hypothetical kotlin dialect
You'd have to create a whole new type wrapping something like an int just to be able to have two different options in the union with the same type
true
i was thinking of making this syntactic sugar
18:11
And Rust enums carry information about the purpose for having those types, while unions don't
but its so complicated
With a Rust enum you can do things way more complicated than an AST, where it would be very unclear what types map to what possibilities, which would be unsuitable for unions
argh fine you won
but im not calling them enums
such a misleading name
Good, enum is a gross word :p
and im still adding union types
18:13
Wouldn't they be redundant?
no
i dont have function overloading
Rust-style enums mean you can merge enums and union types into a single construct
@Seggan Neither does Rust
yeah but its so nice being able to give different types to the same function
besides rust has traits, and i dont
you can simply implement a trait and bam
@Seggan Which you can do with Rust-style enums?
Right?
Just make your "union types" syntactic sugar for an enum
id rather make it the other way
18:17
You can't tho
Enums are a superset of unions
They carry more information
like?
Like...normal enums. How do you represent enum { ThingOne, ThingTwo, ThingThree } with a union?
@RydwolfPrograms unnecessary boilerplate alert
@RydwolfPrograms you dont
How do you represent enum Signed { Pos(i64), Neg(i64) }
im also having java style enums regardless
18:19
@Seggan Then you can't do the other way around
@RydwolfPrograms with wrapper classes
@Seggan What...if you had Rust-style enums, they would replace Java-style ones
It would make literally no sense to not do that
Because they are a superset of them
nope
There is nothing you can do with a Java-style enum that you can't do with a Rust-style one
java style enums are 1. constant and 2. they can have associated information with them
18:20
Wdym by either of those points
i can write in java enum X { Y(1), Z(2); int num; X(int num) {this.num = num}} and then do X.Y.num which gives me 1
useful for making periodic tables lol
Okay admittedly that is kind of cool, but no reason you can't fit that in with Rust-style ones
@RydwolfPrograms by constant i mean that in rust every Option::Some(x) is a different Some object, right?
In what sense
@RydwolfPrograms i cant have both in one
18:23
Binary-wise they are identical
Comparison wise I believe they are identical
yes but they are still different instances across memory, no?
java enums are strictly uninstantainable
Wdym across memory? In the stack or in the heap? If you put it in the heap with a Box or something then ofc the Boxes would be different
But the Boxes would contain the exact same data
let x = Some(1)
let y = Some(2)
2 different Somes, right?
That question doesn't make sense
argh
what im trying to say is you can make more and more of that enum
18:25
Some(1) is basically just a tuple ([Option::Some's index thingy], 1)
in java, the enums instances are all youve got (barring reflection)
Well yeah 'cause they're just ints internally right?
That's all an enum is, an int with names
or with Rust-style ones, an int with names that's the first item in a tuple that can also contain more data
java enums are full on objects
18:27
Well that's dumb
Don't be like Java
Stop it. Get some help.
well i am planning to
Wait hang on what would the difference even be
At a low level
Isn't calling it an object just a choice, but it behaves just like an int with a name? When would it be different?
then all data is ints :P
there is no difference between a string and a horse
@Seggan At some level yes
But those ints can be pointers to more ints
And the numbers of ints varies
And what they mean varies
An enum is just a single int that isn't a pointer, right?
18:29
yeah?
Then it's an int with a name
with possibly data associated with it
A Some(1) is just an int with a name sitting next to an int
all objects are
@Seggan That's not actually stored with the enum value tho right?
18:30
it is
Like I'd assume an X.Y isn't literally stored as ([Y's index], 1)
@Seggan what the literal fuck
Well not literal
But why
java enums are syntax sugar for limited instance uninstantainable objects
Wouldn't you just store a single lookup table that you'd index into?
@Seggan I have no clue what that means but I don't think it matters here
And if you're taking inspiration from Java and it actually does store enums that way my official medical advice is to stop right now :p
@RydwolfPrograms because you can add methods too
and use this and all that coolness
You can do that in Rust, which doesn't do that
I don't see how associated information would at all change whether methods could be added
Or why methods would require storing copies of the associated data all over the place
18:42
@RydwolfPrograms what i mean is the X enum is literally (ive seen the bytecode myself) compiled as class X { static X Y = new X(1); static X Z = new X(2); final int number; private X(int number) { this.number = number }}
@RydwolfPrograms they... dont? thats what i mean by constant
there is only one instance per enum variant
Then this is false?
in C its true
And an enum is just a pointer to a tuple containing the variant and associated data?
@Seggan Yeah sure but we're not talking about C
i thought thats what u meant, my mistake
18:44
ima have to store enums as object anyway, bc lua
@Seggan I have only one reply to this
lol
i forgot the extends Enum but it doesnt matter
@RydwolfPrograms AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Seriously tho we got enums right the first time (then improved them a ton with Rust). Overcomplicating them would be silly.
Java definitely overcomplicates them
blame java "everything is an object even functions and enums"
18:47
@Seggan Why not?
how am i to tell the compiler the difference between constant associated data and parameters
The constant associated data is constant
But actually just ^
Wouldn't they look different?
A type tends to be distinguishable from a piece of data
@RydwolfPrograms i meant as in syntax
Yeah so do I
enum ThisOneHasParamters {
    X(i64),
    Y(String, Expr),
    Z {
        x: Thing,
        y: String
    }
}
enum ThisOneHasAssocData {
    X(16),
    Y(name),
    Z {
        x: Thing { ... },
        y: "Hi!"
    }
}
@RydwolfPrograms (the types are all different here but ignore that; didn't want to make three different enums)
fair enough
18:52
Although I do see why Rust doesn't do assoc data; it would make more sense to put that in like, a match on the enum rather than in the enum itself a lot of the time
Doing both at once might be kind of mutually exclusive for whether or not they're reasonable
yeah thats my point
switches over enums for that purpose are discouraged in java
Yeah but Rust-style is way more capable than Java-style, right? And no reason you can't just have some sort of method that allows you to conveniently use a dict for associated data
it better to (kotlin) enum Element(val atomicNum: Int) { HYDROGEN(1) ...
Imagine if your lang allowed indexing into hashmaps using enum variants
java/kotlin/scala/jvmstuff does
18:54
Isn't that kinda redundant then?
no
its slower
and more verbose
@Seggan Not if you optimize it out
And given the code you showed me that made me do the darwin face I don't think Java enums particularly care about performance
0
A: Sandbox for Proposed Challenges

Parcly TaxelHow spherical is my ellipsoid? (Willmore energy) code-golfmathgeometry Define the (unnormalised) Willmore energy of a surface as the integral of squared mean curvature over it: $$W=\int_SH^2\,dA$$ For surfaces topologically equivalent to a sphere \$W\ge4\pi\$, and \$W=4\pi\$ iff it is actually a ...

That also allows you to store different (possibly conflicting) sets of data for the same enum, or without modifying the original enum
@RydwolfPrograms still better than hashmaps
@RydwolfPrograms huh
18:56
E.g., another library can't add atomic mass to your enum's associated data
true
But it can just define a hashmap you'd index into with the enum for atomic mass
why cant they do a hashmap
AtomicMassLib::Mass[myElement]
also verbosity
18:57
That's also more readable than, what, myElement[0]?
( ͡° ͜ʖ ͡°)
@RydwolfPrograms myElement.atomicNumber
Oh right the weird thing
Also, no reason you couldn't also impl a method onto the enum that uses the hashmap
thats not how i do things in rol
myElement.atomicNumber would then just be identical to AtomicNumber[myElement]
@Seggan So it's not...how you rol? :p
18:58
ಠ_ಠ
no typeclasses
or should i say i dont do oop the way rust does it
D:
But seriously tho I find AtomicMass[myElement] basically just as readable as myElement.atomicMass
@RydwolfPrograms (I feel like I should get more than a gingerface for that pun :p)
oh no
i think a massive wall of text is coming
Coming up with a good name for OTTNB is so hard because it needs to communicate more off-topic than a Nineteenth Byte/Hole, but still needs to communicate "golfing/CGCC"
I think the bowling direction is promising
nvm then
19:02
Especially since without additional restrictions code-bowling is off-topic
Yet code bowling's still clearly a part of our site
the eleventh pin
argh ninja'd
( ͡° ͜ʖ ͡°)
ಠ_ಠ
parz, lenny faces aren't funny on their own y'know
.o.
19:05
They have to be used with careful consideration to maximize their potential
IF THERE ARE ENOUGH LENNY FACES THEY WILL BE
Otherwise we risk building immunity to them
HAHAHAHAHQBHAHHAAHHAHAHAH
Lenny immunity is bad, but nobody can build Comic Sans immunity who is not born to it.
19:53
Oof my 7th grade history teacher used to tell me that
I didn't pay attention in history class and now I'm in a war with Japan over imperial ambitions in Manchuria :/
20:44
@emanresuA The wording here is important: studying history only prepares you for forty years of teaching it. Just learning some history isn't a problem if you don't major in it. And even if you do major in history, you don't have to teach history, you just won't be prepared for any other job. :P </lit-se>
(There has been more than one occasion at my job when I've found it appropriate to sing under my breath, "CS will make each day a quest to find a missing close-paren"...)
21:20
@DLosc when i see a message with only a closing tag i imagine that the corresponding opening tag was somewhere far back and everything up to now has been inside the lit-se/rant/whatever element
 
2 hours later…
22:57
0
Q: Create a triangle whose colors are determined by the bitsums of coordinates

Akiva WeinbergerWrite a program that, for any $n$, generates a triangle made of hexagons as shown, $2^n$ to a side. The colors are to be determined as follows. We may give the triangle barycentric coordinates so that every hexagon is described by a triple $(x,y,z)$ with $x+y+z=2^n-1$. (The three corners will be ...

23:19
Hi everyone!
Hello there!
@AkivaWeinberger Welcome!
@AviFS howdy and thanks for the welcome -- you'll have to forgive my delay, i don't check SE often anymore.
I had a perhaps simpler Haskell question than my other one -- probably doesn't warrant a tips thread. Is there any good way to deal with ambiguous type variables when defining a short form of a function?

[Here's an example](https://tio.run/##y0gszk7Nyfn/PzcxM8@2QMFQy65AIdpQxyiWq0DBykohOCO/XCFRwdYOSOjaKXj6K2hochXYFhRl5pX8/w8A) where I want to shorten `print` to `p`.
23:45
wdym
like what needs to be dealt with
oh i see nvm
huh, i'm actually really surprised the inference works that way
i was a little miffed, on GHC 9.2.5 i believe it inferred Int -> IO () as the type and didn't even ask about the ambiguous type variable.

If I had to guess it would be some quirk relating to typeclasses and monomorphism restriction but I didn't think about it too deeply.
00:00 - 18:0018:00 - 00:00

« first day (4398 days earlier)      last day (742 days later) »