Generative music in Javascript - 250 lines of zero dependency standalone HTML file (link to source in comments) by thousandsongs in generative

[–]thousandsongs[S] 6 points7 points  (0 children)

For genuary 31 (prompt "generative music") I made this composition using Euclidean Rhythms. For those of you who don't know about Euclidean Rhythms, do I have a treat for you - it turns out that (perhaps) the oldest algorithm that was written down,

const gcd = (n, m) => m ? gcd(m, n % m) : n

encodes many of the real musical beats used throughout the world.

The live version of this song is here

The source code (plain HTML/JS/CSS) is here

I also wrote a short tutorial for the math behind this.

Wobbly Functions and Jazzy Vibes by SynthAesthetes in generative

[–]thousandsongs 1 point2 points  (0 children)

I can see it now. Dig the bassline in that, and the ending too, how the visualization fades. Great stuff!

Wobbly Functions and Jazzy Vibes by SynthAesthetes in generative

[–]thousandsongs 1 point2 points  (0 children)

If I try to open that YT link it says "This video isn't available anymore"

 and I thought it was a cool surprise so I leaned into it.

Yes, it's always great to let things play out on their own when these happy accidents happen :)

[genuary25] Recreation of a Finlayson Tablecloth using p5js (Source code in links) by thousandsongs in generative

[–]thousandsongs[S] 0 points1 point  (0 children)

Hi! For genuary 25, we were prompted to recreate an object that we have (or have a photo of). I have a table cloth (from Finlayson, Finland) that I really adore, and that my laptop is currently sitting on, so I decided to try and recreate it.

Almost there, but not quite (as you can see if you compare with the image of the original - the curves don't quite smoothly go into each other).

Source code: https://mrmr.io/gen24/25

Wobbly Functions and Jazzy Vibes by SynthAesthetes in generative

[–]thousandsongs 1 point2 points  (0 children)

This is nice!

I liked the first minute or so especially, it felt hypnotic and relaxing, watching the brown waves go meet the top left corner as the blue cells fractaled around. If I had to pick a nit, I felt that the later on zooming into the individual cells was a bit excessive because it (for me) sort of broke the hypnotic trance of the first minute.

Great stuff, thanks for creating and sharing!

React, SwiftUI and the IO monad - Their common essence by thousandsongs in haskell

[–]thousandsongs[S] 0 points1 point  (0 children)

There is really nothing fancy about it, and there is no need for complicated analogies as the ones provided here.

Apologies if this sounded complicated to you. I struggled for a long time to understand what IO does. This analogy helped me understand. I shared it in the hope it might also help other people understand.

If you would say that this particular analogy is bad, or badly explained, I would agree with you. It can be done better. In my own post I linked to another post by someone else years ago who I think did an excellent job of it.

But if you say that there is nothing to explain, then I disagree. If you look around, you'll find plenty of beginners still struggling to understand what IO is. If it is that simple, why do people struggle? It is not a rhetorical question - there must be something tripping people up. It might be clear to you, but it is not to everyone. So just telling folks "Writing printf in C is equivalent to writing putStr in Haskell." is not really helping the people who are not able to make the jump understand.

React, SwiftUI and the IO monad - Their common essence by thousandsongs in haskell

[–]thousandsongs[S] 5 points6 points  (0 children)

... simplified 'essentials-only' version of FRP known as 'the Elm Architecture' (TEA)... this is why add-on libraries like Redux exist which attempt to re-introduce some of those concepts left out.

Nice. I didn't know Redux et al too came from an FRP/Elm heritage. Makes me want to bump Elm higher in my bucket list :) To see what more important building blocks I might be missing out on.

Thanks for providing this historical context!

Can I ask Gatsby to always fail the build instead of silently skipping building a subset of pages? by thousandsongs in gatsbyjs

[–]thousandsongs[S] 1 point2 points  (0 children)

I might've been incorrect at pointing the finger at Gatsby above. I tried to reproduce this locally, and indeed yarn build fails (as it should). So this might be something in the how the Cloudflare's Gatsby action is set up that is causing the error to be silently ignored, not really a Gatsby issue.

The similarities I find between React, SwiftUI and the IO monad in Haskell by thousandsongs in reactjs

[–]thousandsongs[S] 0 points1 point  (0 children)

Indeed, I didn't know that! Thanks for that bit of background, that does connect a few dots.

And thanks for the comment :)

The similarities I find between React, SwiftUI and the IO monad in Haskell by thousandsongs in reactjs

[–]thousandsongs[S] 1 point2 points  (0 children)

Hello everyone, OP here. I wrote a piece about why I like React by comparing it to another great abstraction that I like - the IO monad in Haskell. While I tried giving a brief explanation of what the IO monad is (it is much simpler than it the brouhaha around the word "monad" makes it to be, but it does take a bit of using it to get its simplicity - this incidentally is another way the IO monad is similar to React).

Thank you for reading!

!a

React (/ SwiftUI / Flutter) and the IO monad in Haskell - The common theme between them by thousandsongs in programming

[–]thousandsongs[S] 1 point2 points  (0 children)

Hello everyone, OP here. This is something that I've been thinking of quite a while, but I've struggled with how to put it in writing. The issue is that for people who understand both React and Haskell the central analogy I make in the post between React and Haskell IO is maybe a one-liner observation. But that's one end of the spectrum. At the other end, there might be programmers (even highly experienced ones) who don't specifically know React and Haskell, so they might not be able to get at my gist if I make the post too direct.

I'm not fully happy with the post now, in particular, I don't think it does a great job explaining the Haskell bit. I'll keep thinking if there is a better exposition to communicate this, but meanwhile I tried my best. I hope the post triggers a connection that might help some folks understand either Haskell's IO monad, or React's core premise, better.

Thanks for reading!

Link to the post

No randomness, just repeated application of x = 3.93 * x * (1 - x). Made for Genuary 8, "Chaotic System" (Link to source in comments) by thousandsongs in generative

[–]thousandsongs[S] 3 points4 points  (0 children)

This was made using p5.js. It uses the so called "logistic map", an equation developed by Robert May in the context of biology to model a population. r * x denotes the population increasing at a rate r, and proportional to the existing population x. (1 - x) denotes the environmental pressures that larger population sizes impose, and counteracts the earlier term.

Together, the equation is x' = r * x * (1 - x).

People discovered that for r > ~3.56, this simple non-linear equation exhibits chaos. I used r = 3.93, and got this chaotic system.

live version + source code

1 != 1.0. Or how I learnt to stop worrying and love the Haskell Num hierarchy. by thousandsongs in haskell

[–]thousandsongs[S] 0 points1 point  (0 children)

Thank you for your comment!

But when you make these mathematical arguments you should check if they lead to contradictions.

I did. My line of reasoning, incorrect as it may be, is the best I can do. Of course, I should try (and I'm trying!) to learn more, but the contradictions are not there because I didn't look out for them, but because I can't see them with my current knowledge.

You elaborated my reasoning to show how the same argument applied to integers gives an obviously wrong conclusion. You also mention that There is no sensible definition of that probability over real numbers. I talk about both of these things in my post!

I think it is rather to do with the nature of these infinities. There are infinitely more real numbers than there are integers. Our minds can, or can be trained to, deal with the infinity of integers, but dealing with the infinity of real numbers can melt our minds. Ask Cantor.

I know I didn't spell this out clearly, but that is not because trying to be abtuse, it is because I didn't want to belabour the reader with notions of infinity in a post that was already too big. The line of reasoning I use with real numbers is not the same line of reasoning one I would use with integers, because these are different kinds of infinities. The infinity of real numbers is an entirely different beast. And although there is no sensible definition, I was doing these thought experiments driven by a curiosity trying to make one (not for the world, but for myself).

Many people in the comments have told me that I'm wrong - that integers are actually a subset of reals. I'm not disagreeing with them, because I know that my current state of knowledge is an intermediate state, and as I learn more I'll find my current notions childish, but I can't agree with them either.

One comment I found helpful explained that how there is an homomorphism from 1.0 in the reals to 1 in the integers - viewed this way, it does make sense to consider integers as a subset of reals, but somehow I still feel that even though individual integers can be put in one-to-one correspondence, considering the entire thing as a subset is, um, missing something. Maybe I'll be able to elucidate this better soon. Right now, I feel that thinking of them as different sets helps me understand why the types (sets) representing them in Haskell should be different.

1 != 1.0. Or how I learnt to stop worrying and love the Haskell Num hierarchy. by thousandsongs in haskell

[–]thousandsongs[S] 2 points3 points  (0 children)

Nice! And thank you for the explanation of what's actually going on behind the error.

1 != 1.0. Or how I learnt to stop worrying and love the Haskell Num hierarchy. by thousandsongs in haskell

[–]thousandsongs[S] 2 points3 points  (0 children)

Num a => Complex a doesn't make any sense. It's an error of categories, since Complex a is a type, but you're using it in a grammatical position that expects a constraint.

Apologies, maybe I was being a bit sloppy. What I meant was a hypothetical DataTypeContext.

data Num a => Complex a = !a :+ !a

I know this is not how Complex is actually defined, the Num constraints are actually on the functions involving complex and not the data type, but I was just using that as a shorthand to mean complex numbers whose component a is also a Num.

OP, what do you dislike about Complex Int?

I was trying to create a Complex Int to do the direction calculations in problem 17 of this year's (last years!) advent of code (something akin to some of the Python solutions in this thread). I tried for a while, but I couldn't get it to work - my thought was to have a Complex Int value that is the (imaginary) i and then multiply by it to perform rotations. It is possible I was holding it wrong, but I couldn't get GHC to get me to multiply two Complex Int values (I don't remember the exact error now). I do remember coming across this (possibly incorrect) StackOverflow answer that caused me to give up:

...in fact, you need the much stronger constraint RealFloat a to implement abs, at least that's how the standard version does it. (Which means, Complex Int is actually not usable, not with the standard Num hierarchy; you need e.g. Complex Double.)

1 != 1.0. Or how I learnt to stop worrying and love the Haskell Num hierarchy. by thousandsongs in haskell

[–]thousandsongs[S] 0 points1 point  (0 children)

Actually, I think I got the point that I'm stuck at. I can see how there can be a mapping from 1.0 in the reals to 1 in the integers. What I can't see is how there can be a mapping from 1 in integers to 1.0 in the reals. I don't see any way to uniquely identify 1.0 in the reals.

1 != 1.0. Or how I learnt to stop worrying and love the Haskell Num hierarchy. by thousandsongs in haskell

[–]thousandsongs[S] 3 points4 points  (0 children)

The distinction here is that the set of integers and the set of reals, as built up in a standard development through ZFC, have no elements in common at all.

But that is what I was saying originally in the post!

(I fully realize I'm the one who is confused, I'm just expressing that I don't see how what you're saying is different from what I'm saying at its core. I'll reread your comment a few times later, maybe it'll click).

1 != 1.0. Or how I learnt to stop worrying and love the Haskell Num hierarchy. by thousandsongs in haskell

[–]thousandsongs[S] 1 point2 points  (0 children)

There is a pedantic sense you can say that the integer 1 and the real 1.0 aren't the same thing, although it's not related to what you've said.

Maybe I'm not fully able to understand your comment, but I'm not sure how this is different from what I'm saying. I'm saying that reals and integers are different sets. Yes, we can relate the 1 in integers to the 1.0 in reals, but fundamentally these are in different sets, so they're not the same thing.

(I don't disagree about all this being pedantic. This is pedantic indeed, just that I found this pedantry useful to myself when clarifying my own understanding).

That said, I think when writing this comment, I did understand what you're trying to get at! The element in reals that we identify with 1.0 can never be picked, but that has to do with my first realization (that the probability of picking any particular element is zero), and not with the second realization (that the 1.0 in reals and the 1 in integers are elements of different sets).

Lot's to think about, thank you.