Programming thread

Monad is category that combines two other categories
Endofunctors and Monoids.

Monoids are defined as group and natural operation that have neutral element and are associative.
So for example addition (with zero) is monoid. So is multiplication with one.
And so are lists with concat and empty list. As [a,b,c] : [] = [a, b, c] and ([a, b, c] : [d]) : [e] = [a,b,c] : ([d] : [e]) = [a,b,c,d,e]

Functors are defined as mapping between categories that preserve structure.
So probably best example is Optional/Maybe.
As anything that is Maybe X can have applied function that are applicable to X.
For example Maybe Int + Maybe Int = Maybe Int (technically you need fmap) etc.
And so is true for lists. As you can apply function to each element of lists the same way as you would to them individually.

Endofunctor just category that maps category to itself.

Now Monads combine Monoid and Endofunctor, they need associative operation with neutral element.
What gives us is a way to combine operations using Bind m a -> (a -> m b) -> m b which you can read as;
take Monad a, unwrap it to get a, apply function to a, use monads natural operation to create Monad b.

Easiest way imho is again to look at lists. Let's say we have function f a = [a, a] . It just takes number and returns 2 numbers inside list.
Now if we take list [1,2,3] and do bind f [1,2,3] we will get [1,1,2,2,3,3]. Why?
Because first Monad will take each element of list and apply function to it creating [1,1] [2,2] [3,3] and then will use lists natural operation, which will be concat, to combine them into [1,1,2,2,3,3].

So the difference between between Functor and Monad, is Functor fmap will only operate on inner values, where as Monadic bind will change context as well.
The IO monad encapsulates the context change in World -> World function. So there is no reall run, it's just a way to enforce that World is never copied, and it is used up after next World is created.

Because IO x = World -> (World, x) . And natural operation for IO monad will be to take resulting World and put it in new World -> (World, x) function.
So
Code:
main = getLine >>= \line ->
             putStrLn line
so if we decompose it:
getLine is gonna take, and return changed world and line world -> (world', line)
then (>>=) bind operator will pipe world' and line into putStrLn which will take it and change world' creating new world'' world' -> (world'', ())
and so on.

That's not really rigorous mathematically, but that's how I understand Monads. Feel free to correct.
 
Can someone explain Monads in a non-retarded way?

From what I understand they're a wrapper type that bind themselves to a value type with a bind function, and then produce a side effect with a run function, which itself wraps around an inner function call, for which the wrapped value is substituted as the function argument.

Am I on the right track or am I retarded?
Hope this helps in a more general and conceptual sense:
The big no-no in pure functional programming is the existence of unmanaged side-effects. But who's to say we can't just manage them instead? What if we reframe our perspective a little and start explicitly describing an environment (or "world") in which these effects can occur? This is where it gets really interesting.

In lambda calculus, recall that lambda functions are curried unary functions. In linear algebra, we pay a lot of attention to linear independence and, consequently, the dimension of vector spaces. What these boil down to is that when describing a multi-variate system, each dimension/independent variable is basically another layer of function compositions. Note the term "layer" is highly relative here.

To draw some heavily simplified real-world parallels, let's consider the motion of water or air molecules as a group. Together, we can model the overall periodic motion of them—seen as a pretty ocean wave or heard as a sound—as a sinusoidal function with some asymmetry. Though, we can model the motion of each molecule, each individual particle, etc. at some arbitrary depth as well. Whether these systems affect the values of other neighboring systems is a physical manifestation of dependence. These are all function compositions that you can define and combine at essentially infinite depths, depending on your level of autism and the task at hand.

So now let's take this idea of arbitrarily deep reference frames and apply it to programming: we can define an action we wish to take in our "world" and we can describe how such action affects the world state. This is typically done using monads. If we ensure the value of a monad is bound in a function that computes another monad of the same type, what we have is a chain of causality, where the result of each action is passed as input needed to perform the next action. The monad acts as an abstraction layer for observing and interacting with our created world, much like how our brains can be seen as computers, possible to model functionally, interacting with an inconceivably huge mathematical model (the Universe) using our bodies to observe and interact with it.
The quote relates to IO stuff, but it's all just encapsulating systems and strapping a bunch of extra bullshit to them.

What's your opinion of how the Python style guide treats things
It is my experience that everything but the Kernel style guide are objectively trash, across all languages.

So I'll put it this way: the python guide isn't great, but it could be a hell of a lot worse.
 
The quote relates to IO stuff, but it's all just encapsulating systems and strapping a bunch of extra bullshit to them.
I like how OCaml and Scala handle things i.e. "make data immutable by default but if you want to make them mutable that is very easy and doesn't require category theory".
It is my experience that everything but the Kernel style guide are objectively trash, across all languages.
>tabs for indentation
 
  • Agree
Reactions: Marvin
and doesn't require category theory
Anyone using category theory is making a terrible mistake. That includes mathematicians.

1743689975885.png
 
Is there a reference I'm missing
the sign is a subtle joke, it says "sneed's feed and seed (formerly chuck's)" which implies that sneed's used to be called chuck's f___ and s___, and the words rhyme. it's very funny when you figure it out
in front of the famous store, homer simpson gets into a bit of banter with the men sitting out in front of the store. the first insult they shout at homer is "haw haw, look at that city slicker in his fancy german car!" which is a clever reference to how city slickers drive fancy cars made by german manufacturers
 
I'm porting some code from C# to C++. As a C# project, there are a bunch of enums as bitmasks. After removing the [flags] attribute they basically look like this:
Code:
CustomTypes.h
namespace Utilities::CustomTypes {

enum class Foo {
e = 0x0,
n = 0x1,
d = 0x2
};

enum class Bar {
m = 0x0,
e = 0x1,
n = 0x2,
o = 0x4,
w = 0x8
};

...
}.

SomeOriginalCode.cpp

bool TestFlags(uint16_t val, Utilities::CustomTypes::Foo flags)
{
    return (val & flags)? true : false; // This is a line from the original code
}

I could overload the & operator on the enums in CustomTypes.h, but there's like twenty of them and if I write an overload for each one it might be prone to errors. So my possibly dumb question is this: Is it possible to write an overloaded & operator that applies to all the enums in Utilities::CustomTypes, but only those ones? I don't want my overload to apply to all enums just in case. Is there a safe way to do this?
 
probably not c++ idiomatic, but this is how you can do it in c:
C:
#define FOO_M 0x0
#define FOO_E 0x1
#define FOO_N 0x2
#define FOO_O 0x4
// and so on for the rest of foo and whatever bars
then when you want to have multiple of them active you can just
C:
doDomething(FOO_E | FOO_O)
other bitwise operators may be used to do things like toggle flags and figure out if only a specific set of flags is active

there's probably some stl class out there that does something like this but with a considerably increased amount of :: and constructor and slightly more type checking
apologies if this is not helpful due to being overly c-focused or from not completely understanding the question
 
If you're actually using the enums as bitmasks, why not just make them plain old "enum" rather than "enum class"?
Because the original source reuses a lot of field names. I could rename them, but then again effort. Plus, I;m not sure that you would just be able to do bitfield int & enum bitmask without casting even with renames. I just wanting a simple way to implement bitwise AND but all the solutions I've found so far just seem like more trouble than they're worth.

I think the hate against C++ is astroturfed so I'm not coming from that place when I say this, but it's funny how the language, for all its strengths, doesn't have a simple, standard way to implement bitmasks (that I can see). :story: FWIW Creative Username's solution works but there is no way to ensure that only correct values are passed to the function, but I do appreciate the responses ❤️
 
Because the original source reuses a lot of field names. I could rename them, but then again effort. Plus, I;m not sure that you would just be able to do bitfield int & enum bitmask without casting even with renames. I just wanting a simple way to implement bitwise AND but all the solutions I've found so far just seem like more trouble than they're worth.

I think the hate against C++ is astroturfed so I'm not coming from that place when I say this, but it's funny how the language, for all its strengths, doesn't have a simple, standard way to implement bitmasks (that I can see). :story: FWIW Creative Username's solution works but there is no way to ensure that only correct values are passed to the function, but I do appreciate the responses ❤️
I used to hate C++ for the longest while but I actually want to give it a shot after trying to do graphics in C. C++ or maybe OOP does actually seem better and more structured for that. But I do still think C++ is pretty big for a programming language.

Unless you use boost, that actually is bloated as shit.
 
  • Like
Reactions: Friendly Primarina
Hi,

I wanted to ask the assistance of the users of this sordid website.

I recently bought this keyboard (Lulu) from Boardsource.xyz.

I had it delivered, and I've installed all the switches into the PCB, and I've installed the PCB into the Lulu-casing. I've made sure that the switches work as well.
Additionally, I have all the necessary cables to make this thing running (I have the C-to-A-cable and the TRS-cable to connect the two halves of the keyboard).

Now, I "just" need to program the keyboard. In order to assist a noob such as myself in this endeavour, Boardsource offers these guides:

Lulu Build Guide:

Lulu Faq:

Lulu Flashing Guide:

Firmware:
QMK:


Now, try as I might, I still can't quite get the operation of this QMK-firmware into place. It's all just so complicated, and I would want the guidance of people accustomed to these things before I try anything out. I've never truly utilized GitHub, for example, simply because it doesn't feel very intuitive for a noob such as myself. I have a hard time navigating the website and making sure how to use it properly.

To put things into perspective, I bought this keyboard back in 2019: the Ergodox EZ.
"Easy" indeed. They have this very user-friendly interface on their website in which you are able to create ("flash"?) the keyboard layout that you want with little more than some simple points-and-clicks.
I very much desire this utility for my Lulu.

What I want to ask you guys is if you could help me to understand how I should go about in creating/mapping/flashing the layout for my new Lulu.
If you are able to help me, please keep it as simple as possible.

Thanks.
 
Lulu Flashing Guide:
This appears to be all you need.
Go to the configurator: https://config.qmk.fm/#/boardsource/lulu/rp2040/LAYOUT
Make your changes. Click 'Compile'. Wait for the potato to finish spinning. Download the Uf2 file(That's the 'Firmware' button). Also, download the Keymap.json with that button so you can upload it for your starting point when you want to make more changes.

Follow the flashing guide: Unplug keyboard, hold the upper corner key, plug in keyboard, you should see a new USB drive. Copy the Uf2 file to the drive. Wait for the drive to automatically disappear when the keyboard reboots.
 
  • Informative
Reactions: Naughty vir
This appears to be all you need.
Go to the configurator: https://config.qmk.fm/#/boardsource/lulu/rp2040/LAYOUT
Make your changes. Click 'Compile'. Wait for the potato to finish spinning. Download the Uf2 file(That's the 'Firmware' button). Also, download the Keymap.json with that button so you can upload it for your starting point when you want to make more changes.

Follow the flashing guide: Unplug keyboard, hold the upper corner key, plug in keyboard, you should see a new USB drive. Copy the Uf2 file to the drive. Wait for the drive to automatically disappear when the keyboard reboots.
Thank you kindly!

I'll try this out tomorrow. I'll let you know how it worked.
 
I think the hate against C++ is astroturfed so I'm not coming from that place when I say this, but it's funny how the language, for all its strengths, doesn't have a simple, standard way to implement bitmasks (that I can see).
c++ doesn't have a simple, standard way to do anything because there is always the c way, the stl way, the other stl way added in 2023, the 4 different boost ways, and the qt way
I used to hate C++ for the longest while but I actually want to give it a shot after trying to do graphics in C. C++ or maybe OOP does actually seem better and more structured for that. But I do still think C++ is pretty big for a programming language.
c++ is a huge piece of shit, but it's a very carefully designed piece of shit made by very smart language designers to make a c variant that is as abstract as possible without needing tons of runtime support
is it a powerful language that can be used for lots of things? yes. is it well-thought-out? mostly. is it elegant? fuck no
 
Back