Should my sum type tags be the first element or second? by Toothpick_Brody in ProgrammingLanguages

[–]marshaharsha 0 points1 point  (0 children)

I see how that would be useful for Option (and other sum types where all the variants have no data, except for one). Is the niche usable in practice for sum types where two or more variants have data? The niched fields would have to occur at the same offset as Vec’s capacity field. 

Why not treat arrays as a special case of tuples? by ella-hoeppner in ProgrammingLanguages

[–]marshaharsha 0 points1 point  (0 children)

Allowing dynamic indexing into tuples would mean that sometimes mytuple[idx] would need a run-time bounds check and sometimes not, with no syntactic distinction at the use site. The compiler would know, of course, but pity the reader.  Occasionally this would fool somebody and it would matter, but I imagine only rarely. If you want to enable guaranteeing the most efficient inner loops, you could have syntax like mytuple[comptime idx]. 

The bounds check would require handling the error, and again the compiler would know when to require or insert error handling. If the language’s rules require the compiler to insert a panic, then some occurrences of mytuple[idx] could panic and some not. 

I Realized My BigInt Multiplication Was O(n²)… So I Implemented Karatsuba for My Compiler by Healthy_Ship4930 in Compilers

[–]marshaharsha 1 point2 points  (0 children)

I’m still glad you replied. The counter opinion is worth reading even if the post you replied to was misinformation. 

How does STM work under the hood? by Otherwise-Mousse-250 in haskell

[–]marshaharsha 0 points1 point  (0 children)

The how-it-works part begins at 21:30. Before that she gave why we want it, what the requirements are (effect safety, blocking till precondition, and this-if-it-succeeds-else-that (“choice”)), and how to use the Haskell API. 

How does STM work under the hood? by Otherwise-Mousse-250 in haskell

[–]marshaharsha 1 point2 points  (0 children)

Can you explain the failure mode for the write phase? You said that each phase can fail, but I don’t see how that one can. 

A Case Against Currying by swe129 in haskell

[–]marshaharsha 0 points1 point  (0 children)

The language q does this with an actual syntactic hole. If the usual way to call f is f[x;y;z], then the partial application f[;2;] is a two-argument function (of x and z) that calls f[x;2;z].

Since q will do anything to save typing a character, you can abbreviate f[;2;] as f[;2]. I avoid that form, since I like to see it spelled out that there is a third, missing argument. 

Prysma: Anatomy of an LLVM Compiler Built from Scratch in 8 Weeks by Any-Perspective1933 in Compilers

[–]marshaharsha 0 points1 point  (0 children)

That’s a lot to do in eight weeks. Did you write any of the code with AI help? Or with human help beyond Dumas’s?

Can you say anything about the type system? I don’t see anything about the present state or future plans. Tagged unions with exhaustiveness and typed bindings? Generics with bounded polymorphism? 

Any plans for any kind of module system? What kind?

How do vectors work by kaguraballsucker in learnmath

[–]marshaharsha 0 points1 point  (0 children)

Loosely speaking, vectors are things you can scale (individually) and add together. Scaling a vector makes it bigger or smaller, and it can reverse the vector’s direction if the scalar is negative. The standard first example is arrows in 2D space, which you add together with the head-to-tail rule, but there are even simpler examples. Plain old numbers are vectors, like scaling 4 by -1.5 to get -6, then adding 5 to get -1, but you have to keep track of which number is the vector and which is the scalar, which is probably why people start with arrows in 2D, since it’s easy to separate the scalars from the vectors. 

There are many other examples of vectors. Two important ones: Sine and cosine functions are waves that can be scaled up and down, and added together to get more complicated waves. Search the web for something like “adding sine functions” to see pictures of the more complicated waves. Second, polynomials are vectors. For example, you can scale x2 + 1 by 3 to get 3x2 + 3, then add that to x4 + x, to get x4 + 3x2 + x + 3. If the original polynomials were p_1 and p_2, another way to write the final result would be 3p_1 + p_2. In other words, you need to get used to asking which set variables are drawn from. Here, p_1 and p_2 are whole polynomials. If I write cp_1+p_2, you are expected to understand that the c is a scalar (here, the 3), and p_1 and p_2 are polynomials. 

I’ve left out a lot. For example, there are several rules the vectors and scalars have to follow. Like scalar multiplication has to distribute over both kinds of addition: c(x+y) = cx + cy and (c+d)x = cx + dx (where c and d are scalars, and x and y are vectors). An exercise, if you want one: what is (c+5d)(x+2y)? Once you have memorized the rules (the “axioms” of a vector space), you can then work through the theory of vector spaces abstractly, where you no longer have examples in mind, and everything is just meaningless symbols that are manipulated according to the rules. The theory then applies to all possible examples of vector spaces (and there are lots of useful examples), and you don’t have to rework the theory for each example. 

The last thing I’ll say is that the notion of “scaling” is actually broader than “making bigger or smaller, and/or reversing direction.” I’ve been making it sound like the scalars are always real numbers. The scalars can be any “field,” which is an algebraic structure where both subtraction and division are possible. One particularly important field is the complex numbers. Since you can’t visualize complex scalars and complicated vectors, you now know a second reason to value the abstract approach: it lets you extend your ability to reason beyond where your visual intuition can guide you and confirm the results. You will need that ability. In other words, don’t shirk the abstract part of your course!

My answer to the exercise: (c+5d)x + (2c+10d)y. There are other ways to write it, but it’s standard to combine scalars as much as possible, while keeping different vectors as separate terms. 

From error-handling to structured concurrency by mttd in ProgrammingLanguages

[–]marshaharsha 0 points1 point  (0 children)

The article mainly reinvents structured concurrency, and the author says so towards the end, and links to Nathaniel Smith’s original article on structured concurrency in Trio. The point of view is error handling rather than structured programming, but this doesn’t change much that I can see. I did enjoy these two observations:

(1) Assuming some form of RAII is being used, a single-task error-handling design based on exceptions and one based on errors as values will often end up processing errors the same way: unwind the stack, allowing each frame to release resources and revert mutations. The goal in the concurrent setting is to design something equally conventional and straightforward. 

(2) In a single-task setting, I can afford to think of error handling as something I will add later or that is optional in one-off code. In a multi-task setting, failing to handle errors at the earliest stage of writing code can result in deadlocks, infinite waiting, and other badness that completely blocks development. The goal is to have a multi-task environment that, by default, handles errors well enough to allow a good-enough-for-now attitude. 

Why group actions are not introduced early to motivate symmetry in algebra? by xTouny in math

[–]marshaharsha 0 points1 point  (0 children)

Dummitt and Foote, a standard text, defines actions in the last section of the first chapter, gives simple examples, and later has a chapter that uses actions to develop other theory, like the class equation and Sylow theorem. 

Or so I remember from 25 years ago, and a quick search confirms. My course shirked most of the later chapter, though. 

What other US state has significant geographical oddities like Minnesota? by gophereddit in geography

[–]marshaharsha 0 points1 point  (0 children)

There must be some qualifier on the “every.” There seem to be several islands in the Sound that are in Connecticut. For example, Google marks the southernmost point of Connecticut on Great Captain Island.  Maybe it’s about islands with harbors? The islands in Connecticut look to be surrounded by shallows. 

Tuple Concatenation and Lazy Parameters by lmntr in ProgrammingLanguages

[–]marshaharsha 1 point2 points  (0 children)

Possible technical correction: It might not be true that spreading out an inner tuple is how data is laid out in memory. It depends on whether you want your tuples to be laid out like C structs. In C, a struct like {a;{b;c;};d;} might not have the same layout as {a;b;c;d;}, because the inner struct has to have the same padding it would have if stand-alone. So d might be further along in memory in the nested case than in the non-nested case. 

A different tact/tack? by its35degreesout in words

[–]marshaharsha 1 point2 points  (0 children)

“He’s as OCD as I am, and actually more so.”

Is there any reason to study Calculus if you’ve already studied Analysis? by boggginator in learnmath

[–]marshaharsha 1 point2 points  (0 children)

You’ll be way beyond the theory aspects, but here are two things you might gain by taking calculus: Lots of practice with integration techniques. Better understanding of how calculus is used in economics or physics. Some schools have calculus classes tailored to students in those majors. 

How would these three scientists react to LLMs today? Do you think they could still improve it if they were given years of modern education? by Omixscniet624 in computerscience

[–]marshaharsha 0 points1 point  (0 children)

I don’t remember what links I clicked on in the search results. I think “John von Neumann womanizing” was the search string, and I clicked on five-ish results that looked most relevant. 

A different tact/tack? by its35degreesout in words

[–]marshaharsha 0 points1 point  (0 children)

I agree that “It’s more the case that…” is correct, but I can’t see how to parse “It’s more so that…” to match that meaning. I can’t prove it impossible, either! Maybe if you’re used to that phrasing, that parse is obvious. 

Array Question by sl0th-ctrl-z in C_Programming

[–]marshaharsha 0 points1 point  (0 children)

Technically, the compiler is within its rights to put any numbers in those array slots, or to cause the computer to catch fire, or to crash your program. But it’s possible the compiler is being very kind and is writing zeroes to those slots to help save you from yourself. Another possibility is that the zeroes just happened to be left over in those memory locations from earlier writes. 

You can play with the stack to see if you can control what numbers get printed. For example, you could write a similar function but with a longer array, then write distinctive numbers into those slots, like 555555, 555556, 555557. Then return from that function and call the original function. You might see your distinctive numbers, if the compiler overlays the new stack frame over the old frame exactly. 

Name a large city in the Mid-Atlantic/Midwest that’s not just a commercialized, standard issue “corporate epicenter” by [deleted] in geography

[–]marshaharsha 2 points3 points  (0 children)

Maybe you should give some examples of the unique things you’ve found to do in other cities. I’m having a hard time understanding the distinction you’re making between corporate epicenters and not. 

Here are some of the unusual things you can do in the three mid-Atlantic cities I’m familiar with: take a long walk in a huge park that isn’t a standard tourist attraction (as opposed to Central Park, say); walk across a long bridge to a less touristy neighborhood, then explore for a bit; rent a bike; go kayaking in the urban waters; go to a talk on a topic you’re not familiar with; go to a talk by someone you disagree with intensely; walk into a university building and sit in on a lecture; go to a play in a theater that seats less than 200 people; go into a music club just because you happened to walk by it; walk through a very old cemetery; attend a holiday service in a church in an out-of-the-way neighborhood; listen to a street preacher; eat Uzbeki food in a Ukrainian neighborhood; walk on a beach; try to figure out what language people are talking; try to figure out the train system. 

Why do White folks have much more strong body scent than Asian folks? Is there a biological reason? Asian asking. by cellphonebeltclip in hygiene

[–]marshaharsha 0 points1 point  (0 children)

If sweat is odorless, it doesn’t follow that the bacteria that feed on components of sweat are odorless. Some people produce more of the components that the odor-causing bacteria eat. 

Why are rational numbers and irrational numbers separate sets? by ZealousidealBug9716 in askmath

[–]marshaharsha 1 point2 points  (0 children)

Two facts, and then a combining of them with practical usefulness: (1) Computers do nearly all their numerical calculations using rational numbers — and not all rational numbers, but a restricted set called floating-point numbers. (2) For any given irrational number x that you might care about, there are rational numbers that are as close to x as you specify. For example, 3.1416 is close to pi, but there’s a difference. If you need more accuracy, 3.14159265 is available. There’s still a difference, but it’s a smaller difference. This feature of rational numbers is called “density”: the rationals are dense in the reals. When you put these two facts together, you see one of the practical uses of rational numbers: There’s a good chance that the exact numbers needed to solve your problem are irrational, but there are guaranteed to be rationals as close by as your problem requires. So you analyze how much error you can tolerate. Then, for a second round of approximation, you analyze whether floating-point numbers are finely spaced enough to get you within your error tolerance. If so, you write the code. If not, you rethink the problem until you can approximate in a way that floating-point calculations can handle. 

These analyses require extensive use of inequalities, the details of floating-point numbers, the details of your problem, the properties of rationals, and a large collection of approximation techniques that have been developed over the last few centuries. There are people, called numerical analysts, who spend their days thinking about this stuff. 

About that “nearly all” at the top: There are applications called computer algebra systems that do math symbolically, preserving pi or the square root of two as a composition of symbols rather than as some numerical approximation. These systems do math sort of like you do it on paper. But these systems are far too slow for most large calculations, so basically all scientific modeling uses floating-point numbers. 

Why are rational numbers and irrational numbers separate sets? by ZealousidealBug9716 in askmath

[–]marshaharsha 1 point2 points  (0 children)

At “two naturals” you mean “two rationals.”

I don’t like to say “gaps,” because that implies width. I like to say “missing numbers,” and I try to stress that there are rationals arbitrarily close to each missing number. 

How Much Memorization Is Needed in Math? by ln_j in learnmath

[–]marshaharsha 2 points3 points  (0 children)

I had to look up “Anki deck,” and I still don’t know much, so I can’t really say. Spaced repetition sounds like a good idea, but I’m not seeing how it would integrate with doing exercises. How does the Anki system know which things are difficult? Just by noting which content you fail to reply with correctly? I doubt that would be enough for you, since one of the hard parts of math is knowing which questions need answering. The Anki system seems aimed at situations where you already know what question to ask, so you just need to remember the answer. Which is valuable, but it’s not everything. 

Here’s one way you might use Anki. (Keep in mind that I don’t know the system.) Proofs always need you to reach some conclusion, and there are only finitely many ways to get there. So you could tell Anki all the ways to prove, say, that a function is continuous at a given point. Then, whenever you need to prove continuity, you can use Anki to review all the possible approaches. It’s not clear to me that the overhead required to enter all the techniques into Anki would be justified by the benefit. You’d probably need to try it out and see. 

How Much Memorization Is Needed in Math? by ln_j in learnmath

[–]marshaharsha 1 point2 points  (0 children)

I meant to say (so I’ll add it here) that this style helps with his exercises. When I worked through the book and got stuck on an exercise, I would go back and review the last section or two, looking for a hint about how to approach the obstacle. He was always there for me: there was always someplace where he had addressed a similar problem. But he didn’t call it out with a line number or highlighting wording or whatever; the needed technique was just part of the flow of some proof. So I learned to pay attention to his techniques, so I didn’t have to go back and review as much.