I’m new to programming, but I’ve been reading about tech for a while. I noticed that one language that gets mentioned quite often is Haskell. Could someone explain what’s the big deal with Haskell? Why do people push it so much? Trying to learn.

  • Ravn
    link
    10
    edit-2
    3 years ago

    In addition to my other comment (which is more about paradigms than Haskell in particular), I think the main draws of Haskell is that it’s the most well-known statically typed and pure functional language out there. It’s mature, has a reasonably large community and an OK ecosystem. (I say OK rather than good because it’s rather lacking in some areas like GUI bindings and gamedev but sort of makes up for it with solid “backend”-oriented libraries.)

    It strikes a nice balance of type safety, convenience and readability compared to other languages that feature more expressive type systems and safety guarantees, or impure and untyped functional languages which may be more “straight forward” to use but may bite you in more complex projects with hard to find IO- and type-related bugs.

    The syntax is clean and terse, reducing boilerplate and visual noise for reading and writing, letting you allocate your mental energy to the concepts and semantics more than the details of implementation and technicalities. You spend more time thinking than looking when reading source code, or typing while writing it.

    The type system is expressive enough to act as documentation in their own right (not to say they replace comments and actual documentation!), while also offering escapes for when you think yourself cleverer than the type checker, such as when an edge case really isn’t much of a problem, or when you know something makes sense but don’t wish to prove it.

    It’s lazily evaluated, which enables you to think less about the operational semantics and more about the concept you’re trying to encode. You can compose and chain operations on very large lists or sets without having to worry about the programme iterating over all of it and evaluating everything; it will only evaluate exactly what you need and no more than that.

    I would write more but I’ve procrastinated enough for today…

  • @qoheniac
    link
    5
    edit-2
    2 years ago

    deleted by creator

    • @uthredii
      link
      53 years ago

      What do you find more fun?

      • @qoheniac
        link
        7
        edit-2
        2 years ago

        deleted by creator

        • Ravn
          link
          6
          edit-2
          3 years ago

          It does force you to think more before you write code, but how much depends on the complexity and requirements of the project.

          In a pure functional and statically typed language like Haskell it is even more true because it will let you know about all the things that could go wrong or that don’t make sense. You’ll be made aware of possible failure which allows you to consider the possible divergences before they’ve occurred and handle them gracefully rather than just produce a runtime error and undefined behaviour.

          Consequently, things like reading and parsing a file will often be more involved because success can never be guaranteed when the programme depends on an external state like the file system, and so the compiler demands that you either work with the cases of failure or at the very least explicitly ignore the risks by producing an error (hopefully with a useful message).

          I for one am sick and tired of languages that force me to run my programmes and test for all possible edge cases just to find silly type inconsistencies, typos, bad assumptions or dangerous operations that are likely to fail sooner or later. So I’m quite partial to helpful type checkers and static safety guarantees.

          Note that imperative vs functional is orthogonal to both purity and type safety. Rust is about as safe as Haskell but is predominantly imperative. Schemes like Clojure, Racket and Guile are about as safe as Python, but are decidedly functional while the latter is not. There are also pure functional languages that are untyped, like Nix (which simply doesn’t do any IO at all, at least directly).

          Besides functional and imperative languages there are also logic programming languages like Prolog and Mercury. The former is an interpreted and rather unsafe language while the latter goes a long way to ensure that a programme is soundly typed and safe by introducing statically checked determinism, resource usage constraints (like only opening, using and closing a file once and in the right order - this is known as type linearity or uniqueness) and “modes” (which basically is: which function or predicate arguments can act as outputs from which inputs; allowing functions to act in reverse or predicate arguments can act as either inputs or outputs depending on which are known (“ground”) at that point, which is really cool).

  • @Anti_Antithesis
    link
    23 years ago

    It is genuinely different from many other languages, while also having enough of an ecosystem to allow you to write useful programs. For me, my brain likes how Haskell works, but I am probably in the minority with that. In programming discussions like these, I don’t think enough credit is given to the idea that people’s brains are just different, so if you check it out and don’t like it, its all good.