• squaresinger@lemmy.world
    link
    fedilink
    arrow-up
    48
    arrow-down
    1
    ·
    2 days ago

    Why do programs written in Haskell not have side effects?

    To have side effects someone would have to run the programs.

    • ultimate_worrier@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      2
      ·
      10 hours ago

      Of course, they have side effects. Side effects are what the computation does. Otherwise, they would simply make the box hot.

      The difference between Haskell and most languages is that Haskell forces one to keep that impurity at the outer edges. It enforces that constantly, making programs easier to reason about.

      I heard it explained succinctly lately: types are all of the possible inputs and inputs of a program while functions encapsulate the mutation. Excel, for example, is a purely functional language.

      • squaresinger@lemmy.world
        link
        fedilink
        arrow-up
        5
        arrow-down
        3
        ·
        22 hours ago

        Yeah, there’s like two projects that use Haskell. Doesn’t change the fact that it’s the language that most people know and will never write anything productive in it.

    • Fisherswamp@programming.dev
      link
      fedilink
      arrow-up
      3
      arrow-down
      8
      ·
      22 hours ago

      Listen I absolutely love rust but it’s not even close. Typescript’s type system is orders of magnitude more powerful, to the point where it is actually turing complete.

      • ultimate_worrier@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        4
        ·
        edit-2
        11 hours ago

        Typescript doesn’t have linear types. Not even Haskell has linear types (correction GHC has had LT by extension since 9.0). Give Rust some credit for having linear types (AKA borrow checker).

        Ps. Typescript doesn’t have dependent types and their type system is a joke even compared to Purescript. Here’s a little writeup about it: https://lemmy.dbzer0.com/post/66729809

          • ultimate_worrier@lemmy.dbzer0.com
            link
            fedilink
            arrow-up
            1
            ·
            11 hours ago

            Thanks. I think it’s most fair to count what a language has without extensions but thanks for the correction. To that end, Haskell basically has Dependent Types now too if you pile 10 extensions together (singletons, linear types, and others) and squint a little. It’ll easily be the first production-grade language to do so.

            • gedhrel@lemmy.world
              link
              fedilink
              arrow-up
              1
              ·
              55 minutes ago

              That’s not realistic or “fair” - most Haskell projects will use a dozen or so extensions easily. GHC has been a platform for language experimentation for a long time; standardisation efforts keep on cropping up in annual surveys. (Eg, swapping in Text for String in base is long overdue, but it’s a hold over from days where FP pedagogy was seen as more important.)

      • foenix@lemmy.radio
        link
        fedilink
        arrow-up
        2
        ·
        22 hours ago

        I code a ton in both Rust and Typescript for work… I think Rust has just as capable of a type system, but leveraging macros for functional defs vs object ones.

  • Redkey@programming.dev
    link
    fedilink
    arrow-up
    14
    arrow-down
    3
    ·
    1 day ago

    I started programming in a time when the idea that the computer could keep track of your variable types for you automatically was a fever dream, so it’s wild for me to see some programmers now throwing shade at particular langages for “not implementing proper variable typing functionality”.

    It feels like someone saying that low-fat milk producers are too cheap or lazy to put enough fat in their milk.

    Fashion really does go in cycles.

    • calcopiritus@lemmy.world
      link
      fedilink
      arrow-up
      11
      ·
      16 hours ago

      It was a dream when it wasn’t available. Once it existed, we saw the many flaws it had. That’s why statically strong typed languages still exist. And even new ones are being created.

    • squaresinger@lemmy.world
      link
      fedilink
      arrow-up
      9
      ·
      22 hours ago

      Fashion really does go in cycles.

      This here.

      When I got into programming I figured it would be mostly linear technological progression. Every once in a while something new gets invented that’s better than the last iteration, so we discard the last option (except for legacy stuff) and everyone moves to the better thing.

      But since then everything that was cool back then became uncool and cool again at least once.

      I like the SQL/No-SQL cycle. SQL is powerful, but it’s also slow and clunky and if you do it badly it gets really slow. So we invented No-SQL DBs. They are fast, lightweight, but also barebones and limited. So we add functionality here and there, and before we know it we have another variant of SQL with a different syntax. So we head back to use real SQL. But then we realize it’s slow and clunky and if you do it badly it gets really slow. So we invent a new No-SQL DB and the cycle continues.

      • Feyd@programming.dev
        link
        fedilink
        arrow-up
        5
        ·
        16 hours ago

        It’s more that nosql makes sense of you have very specific performance characteristics and can accept very specific constraints.

        Alternatively, you want to use a document db because you don’t understand that delaying implementing schema integrity or implementing it yourself in the application layer instead of having it baked into your database will be more complex and slow you down in the long run. RDBMS isn’t slower than a generic document DB.

    • CanadaPlus@futurology.today
      link
      fedilink
      English
      arrow-up
      11
      ·
      1 day ago

      I don’t even think it’s fashion. Some ideas sound good but are bad. Or, overlappingly, are convenient to use but actually turn into nightmarish spaghetti code. I don’t know how many people are still pushing MongoDB and BASE, for example.

      Meanwhile SQL hasn’t changed, and C didn’t until someone figured out memory safety in Rust.

      • Redkey@programming.dev
        link
        fedilink
        arrow-up
        5
        arrow-down
        1
        ·
        1 day ago

        Sorry for not being clear; when I said “keep track automatically” I meant dynamic typing. Of course you’re right that “keeping track of your variables” could also be interpreted to refer to static typing.

        • chonglibloodsport@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          18 hours ago

          Haskell keeps track of your types automatically. You can ask it “what is the type of this expression” and it will infer it for you. Haskell is of course fully static typed (types erased at compile time).

  • onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    15
    arrow-down
    5
    ·
    2 days ago

    The same reaction whenever I look at haskell. A “pure” language with an escape hatch that has a fancy name. Once you open the escape hatch, you can write entirely impure code in Haskell and never see a pure function in your life. So much for “pure”.

    • chaos@beehaw.org
      link
      fedilink
      arrow-up
      21
      ·
      1 day ago

      You say your house is clean, yet nothing’s stopping me from dumping out this bucket of mud on your floor, curious!

      • Redkey@programming.dev
        link
        fedilink
        arrow-up
        3
        arrow-down
        2
        ·
        1 day ago

        Reading current discussion, it seems more like “You say that it’s impossible to dirty your house, yet nothing’s stopping anyone from dumping out this bucket of mud on your floor, curious!”

    • the rizzler@lemmygrad.ml
      link
      fedilink
      arrow-up
      2
      ·
      1 day ago

      the only languages that don’t have an escape hatch of some sort are languages with no safety in the first place. the escape hatch is an important part of treating your developer like an adult

  • marcos@lemmy.world
    link
    fedilink
    arrow-up
    6
    arrow-down
    1
    ·
    2 days ago

    Are extensible records usable already?

    Not that I would pick TS because of that, but the disdain is undeserved when it has some very useful features that Haskell has been trying to copy for years.

    • ultimate_worrier@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      9
      arrow-down
      1
      ·
      edit-2
      1 day ago

      The features Haskell has been “trying to copy” from TypeScript are, without exception, features TypeScript copied from type theory research that predates TypeScript by decades – row polymorphism from Didier Rémy’s 1989 work, untagged unions from the intersection type literature of the 1980s, type-level computation from Martin-Löf’s 1975 intuitionistic type theory – and what you are observing is not Haskell enviously watching TypeScript and taking notes, but rather two languages drinking from the same well of ideas, one of which is doing so with a formal semantics and a proof of soundness, and the other of which is doing so while standing in a JavaScript runtime and hoping no one looks down.​​​​​​​​​​​​​​​​

      Purescript > Typescript