Log in | Sign up

  • 0 posts
  • 58 comments
Joined 2 years ago
Cake day: January 22nd, 2024
  • elm is easily the loveliest programming language of any paradigm I’ve ever come across. Imagine if you enjoyed maintaining an old codebase, or that five years later adding a new feature wouldn’t take you half a day to get your had round the insane tangled spaghetti of your project, because the spaghetti and the meatballs and the sauce were always kept separate until cooked and served on the dish by the compiler. You find the spaghetti straight and in bundles because that’s how you like them laid out and no one tried to get you to soften them in the warm sauce and thread them through the raw meatballs. Imagine if the compiler did your whole project in about three to five seconds, and was genuinely helpful when something is going to bite you later.

    Get your monad burritos here: https://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/

  • I’ve been through phases when I could explain it, and in far simpler terms, less jargony, than endofunctors

    A monad is when you can do shit and return stuff. There are two things you can do in absolutely every doShitAndReturnStuff:

    1. andThen, also known as ; in less flexible languages and >>= in more esoteric languages.
    2. And return also known as
      function ret(const a)
      { ret = a
      } in other languages.

    There are two rules:

    1. (a then b) then c = a then (b then c), which sounds obvious, but I skipped a couple of values being passed (I’m using the kleisli category), and it can actually go wrong, which means that if you don’t have a monad but behave like you do, all sorts of subtle and very hard indeed to debug errors can sneak in. See “software complexity problem” for details.
    2. ret then somethingrother = somethingorother = somethingorother then ret, which would seem obvious to you if you spotted that ret does nothing, but for fun, it turns out that in a language with a sufficiently advanced/flexible/accurate type system (eg Hindley-Milner stuff), of you manage 2 you get 1 for free, which is totally awesome.

    “But what’s the point?” I hear all the Python devs say “We already got rid of the curly brackets. What more do you want?” (Which starts a flame war with the C syntax folk while the elm programmers shake their head and wonder why anyone is manually formatting their code whether it’s with curly braces or not in 2026).

    Well, the point, my dear internet Lunatics that have persisted with this fairly unhelpful and daft re-expression of monads, the point is: what if you could redefine ; locally to totally rewire your programming language and everyone was used to that and understood what you were doing from context? Yesterday it was making database requests, but today it’s answering queries on a server. Or authenticating users from the other side of the globe. Maybe now it’s a recursive descent parser or a non-deterministic, expanding list of possible future moves in a game.

    It’s totally awesome and powerful and you just don’t know that you’re missing it because you have no idea unless you already know, but that’s not really helping anyone that doesn’t already understand monads, sorry. Not that this was a plausible attempt at that. It’s more just a bit of humour if you already came across monads. Famously a monad is like a burrito more than anything else.

    But unfortunately there are also monad transformer stacks. And… …operator soup for lenses and prisms. And trust me, you don’t want to go there, you really, really don’t. Just don’t go there, I’m telling you, don’t. DID YOU LIKE BEING SANE? I WARNED YOU, REMEMBER.

  • Everything you said is how I feel. I was enjoying reddit until the Brexit referendum, which was when it felt like it got taken over by the alt right. When the API thing came, I realised that money was the only thing that mattered and they were selling my discussion space to whoever would spend, and the alt right was spending big. We didn’t matter, so like you, I left.

    I was delighted to find people talking again here on lemmy.

  • Afaik, python does both (regular) garbage collection and reference counting. But that’s not why Python is much slower. Python is much slower because it’s interpreted rather than compiled. Like Java, bytecode is interpreted at runtime. Your jit won’t beat compiled haskell, c or rust in most cases. It’s good because it’s based on real profiling of your actual running code, which not every hand rolled premature optimisation is, but it’s limited. I don’t see the spineless tagless G machine (or whatever the geniuses in Glasgow have come up with these days for ghc’s runtime under the hood), as an interpreter, and haskell compiles the whole thing down to native machine code anyway. Machine code is just faster unless you’ve made some asymptotic error.

    I don’t think rust is old, and I’m not trying to tear it down. I’m saying that you can have in place mutation, free on leaving scope, no garbage collection but yet no linear (affine) type system and hence no cumbersome terminology and notation. You can just write lovely functional code and it’s all compiled very well.

    Roc is like Haskell without the monad transformer stack, just one do-everything monad for each application domain (so no one needs to know what a monad is), partial application but you get to specify which argument is to be filled (not just the final one), and you don’t need to know whether you wanted =#~ or &+~ to change something in your nested data structure. (I always found lens to give the most unhelpful errors ever.) Add super fast compilation (seconds, not minutes, even the first time) and genuinely helpful error messages (you know what I mean if you’ve used elm much).

  • Well if you’re calling any form of automatic memory management garbage collection, then it’s only C that doesn’t have garbage collection.

    Rust does have explicit reference counting with Rc<T> and Arc<T>.

    I’m trying to explain to you that static analysis that limits references to one can be done in a similar way without the limit of one (especially with the assumption of immutability) whilst retaining in-place mutation where the count really is one. It upsets you when I try to explain that it’s a generalisation of the borrow checker (without the programmer pain) by calling the borrow checker a static (compile time) reference counter with a limit of one. I’m making a comparison. But don’t be surprised if a lot of programming languages implement their boolean variables as an unsigned int with a maximum of one.

    If roc does the equivalent of putting a call to drop where there were two or three references that fell out of scope rather than one, in what sense is that more overhead than rust calling drop when one reference went out of scope? Rust is still “garbage collecting” the references that turned up on the RHS of assignment statements as it goes along.

    The overhead we’re talking about with reference counting is like DEC r BRZ. It’s like array bounds checking. Yes, it’s an overhead, but no, it’s not worth making a big deal about it if you get to allocate arrays of sizes unknown at compile time or you get to make multiple references without messing with keywords and reference symbols, fighting the borrow checker all day long or manually adding clones.

    It says some overheads. It’s different overheads,

    What? Overheads are overheads. Either they’re small and useful like roc’s reference counting when it turns out to need to be at runtime or array bounds checking, or rust calling drop when some variable falls out of scope, or they’re big, stop the main thread at random points and take a long time, like garbage collection in garbage collected languages like java.

    Why say more if it’s ignored anyway?

    I know - I wrote a whole bunch of stuff and this other person just ignored every single nuance and explanation and kept saying the same thing again and again without trying to understand a new thing they didn’t know about before, just repeating their favourite criticisms of other programming languages whether they applied or not. Oh wait, that was you.

    I don’t think I’m the zealot here.

    Interesting.