Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ Revisiting Haskell after 10 years

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š Revisiting Haskell after 10 years


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Happy new year, dear readers! ๐Ÿฅ‚

The beginning of the year kickstarts the urge of many people to write a retrospective post. Iโ€™m gonna do something a little bit different. I wanna talk about the Haskell programming language and what it looks like nowadays in comparison with 10 years ago according to my perspective.

Iโ€™m by no means a Haskell professional. Itโ€™s just a programming language that I sometimes play with for fun in my spare time and, spoiler alert, I enjoy it a lot. It may be biased since itโ€™s my perspective, so bear that in mind.

Back to the past

My history with Haskell started almost by accident. I wanted to experiment with a programming language different than what I used to work with back then (Java, JS, and Ruby). There was this publisher in Brazil called Novatec where I used to buy programming books, and I bought this Haskell book:

Haskell uma abordagem prรกtica

This was my first contact with the language, and it indeed proved to be very different!

My first impression and experience

The first impact I had in 2014 when I started reading the book was the fact that the language had type inference. As someone who had C and Java classes in college, and did Java professionally at the time (and a bit of C# and ActionScript prior), Iโ€™ve given up on static typing until I tried Haskell. Why, you might ask? The Java tooling wasnโ€™t so easy to work with at the time. Lots of crashes, IDEs misbehaving, and some projects had awful proprietary tools and frameworks involved, not to mention Java 5. I was delighted with Ruby and how fast the feedback loop was, and Bundler to manage dependencies simply didnโ€™t stay in my way, it just worked. Anyway, Haskell restored my faith in static-typed languages, as readability and succinctness had not to be given up in exchange for correctness and speed.

If youโ€™re curious to know what Haskell code looks like, hereโ€™s an example:

import Data.List

wordCounter phrase = 
    nub $ map (\x -> (x, length $ filter (== x) words')) words'
    where words' = words phrase

And the output of the function call:

wordCounter "cow potato chicken potato nugget monkey potato cow potato"

-- [("cow",2),("potato",4),("chicken",1),("nugget",1),("monkey",1)]

Soโ€ฆ

Soon I realized that Haskell was weirder than I thought. Yes, Iโ€™m talking about performing side effects. There was no concept of mutable variables, and to perform any side effect you had to use monads. I got stuck for quite some time using simple IO functions to read-write to the terminal, staying away from complex operations such as read-write to databases, spinning up web servers, and monad transformers to name a fewโ€”I will come back to transformers later.

This kind of challenge tends to repel learners given its steep learning curve but I was amazed by how I could track which function was doing certain side-effect operations by simply staring at the function definition, and how mutability was widespread and dangerous in C-like languages in comparisonโ€”though I could not make correct use of this power at my will yet.

In terms of tooling, there were:

  • GHC, the main Haskell compiler
  • Hugs, another known compiler in vogue at the time
  • Cabal, the building and packaging tool

Compiling programs using cabal was quite nice, as the tool provides all the common use cases you need during development. Adding third-party packages from hackage was most times straightforward, but using packages from other sources or packages conflicting with another package version you had specified on cabal was a nightmare. After 1 year, I guess, stackage appeared, but I had stopped with Haskell by this time.

I remember having a fun ride with Haskell, learning about performing side effects using monads, and writing immutable code by default. It changed how I was writing code in other programming languages, as it made me aware of how many uncontrolled side effects I was performing unconsciously, and how bad it could be for large applications. The code might look alien when you start but soon you get comfortable with it and start appreciating the conciseness. Just donโ€™t take it too far and abuse symbols to write functionsโ€”maybe a topic for another post.

I had stopped with Haskell but the learnings remained. I still remember when I started slowly refactoring some parts of a Ruby application that I used to maintain, leading to an increased speed to run the test suite, by simply postponing some side effects and setting some boundaries on where it was allowed to do it or where it was forbidden.

Summarizing, the good parts:

  1. The Haskell syntax seemed beautiful to my eyes.
  2. The tooling wasnโ€™t great but it wasnโ€™t that bad.
  3. The GHCI, the Haskell REPL, is super helpful.
  4. I enjoyed a lot the fact that I could use Vim to write code in Haskell just like I used to do with Ruby and JavaScript.

Not everything was always a cakewalk:

  1. I remember missing autocomplete but since the syntax wasnโ€™t heavy I didnโ€™t bother too much.
  2. The compiler had some very cryptic error messages for a newbie.
  3. Solving dependencies among conflicting packages was a real pain.
  4. Monad transformers tricked me for a quite long time and I almost gave up.
  5. Compilation time was too long if youโ€™d rely on many third-party packages.

Fast-forwarding to 2024

Haskell looks practically the same. It has new improvements but it has not become a different language. I still have the same feeling as the fond memories of 10 years ago.

I recommend this article about what has been introduced in GHC 2021 (the most recent Haskell language standard):

What's new in GHC 2021 - by Chris Martin - Type Classes

A complete overview of the modern Haskell defaults

favicon typeclasses.substack.com

The tooling evolved A LOT for the better!

The compiler now shows more helpful error messages and GHCup allows us to manage multiple versions of GHC, Stack, and HLS (Haskell Language Server) in a breeze. Compilation time is faster now, but I believe it is because hardware has become faster over the years. Unfortunately, cross-compiling is not yet as simple.

The advent of language server protocol made possible the creation of HLS (Haskell Language Server), and there are plugins for many editors, such as vscode-haskell, that allow you to have auto-complete, auto-import, and automatic function signaturesโ€”also available to your editor of choice. The whole feedback loop of editing, compiling, and running is greatly improved.

Writing Haskell programs that rely on third-party packages is still an issue when itโ€™s a not actively maintained package. They get out of date with the base library (Haskellโ€™s standard library), and you might see yourself in a situation where you need to downgrade to an older version. This is not exclusive to Haskell, but it happens more often than Iโ€™d like to assume. However, if you only rely on known well-maintained libraries/frameworks such as Aeson, Squeleto, Yesod, and Parsec, to name a few, itโ€™s unlikely you will face troubles at all, you just need to be more mindful of what you add as a dependency. Thereโ€™s stackage.org now, a repository that works with Stack, providing a set of packages that are proven to work well together and help us to have reproducible builds in a more manageable wayโ€”not the solution for all the cases but itโ€™s good to have it as an option.

Monad transformer is one topic that made me lose countless hours going from book to practice and back in the past, but thereโ€™s more content available nowadays (books, websites, user groups), and you can also fire questions to an LLM to diminish your feedback loop as if someone more experienced was at your side showing you how to do it. I wish I had this at my disposal back in the day.

Haskell books worth mentioning

Effective Haskell

The Effective Haskell is the most recent book about Haskell, as of now. Not my favorite, but it is full of exercises to practice, and the last chaptersโ€”Building Efficient Programs and Programming with Typesโ€”are insightful.

Learn You A Haskell

The LYAH is by far my favorite book for beginners, however, it lacks exercises for you to practice, but you can still move along typing and playing with the examples shown, and itโ€™s free to read online. Itโ€™s outdated but most of the code may still be valid with little to no changes.

Real World Haskell

The Real World Haskell book is also outdated, but can also be read online for free, and has many examples and exercises on writing practical and usable applications. Although I have not read the book to the fullest, I still recommend its monad transformers chapter, as it was the one that made it click for me.

Wrapping up

Iโ€™m excited about Haskell again! It sits in a very good spot giving its users the expressiveness and conciseness of modern languages with a good performance when you need to squeeze your hardware.

This post has become far too long and almost no Haskell code has been presented to curious readers. Soon I will write about my experience rewriting a command-line application in Haskell with substantial code to show. Stay tuned!

See you on the next one โœŒ๏ธ

If you liked this post, consider subscribing to my newsletter Bit Maybe Wise.

You can also follow me on X and Mastodon.

...



๐Ÿ“Œ Revisiting Haskell after 10 years


๐Ÿ“ˆ 49.27 Punkte

๐Ÿ“Œ Revisiting Glupteba: Still Relevant Five Years after Debut


๐Ÿ“ˆ 33.38 Punkte

๐Ÿ“Œ Haskell-Tutorial: Haskell lernen leicht gemacht


๐Ÿ“ˆ 31.78 Punkte

๐Ÿ“Œ Integrated Haskell Platform: Rapid Prototyping mit Haskell und Nix


๐Ÿ“ˆ 31.78 Punkte

๐Ÿ“Œ 5 Years of Haskell in Production


๐Ÿ“ˆ 23.41 Punkte

๐Ÿ“Œ Shamoon malware revisiting Saudi Arabia; cyberinfrastructure on high alert


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ This October, Revisiting Our Shared Responsibility To Stay Safe Online


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the Top Security Threats of 2017


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the Arcan Project (from the-cool-as-hell dept.)


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the Mladiฤ‡ Trial Amidst Trump Adminโ€™s Attacks on International Criminal Justice


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the Jobs Artificial Intelligence Will Create


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting Carter Page


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting General Counsel Neyโ€™s Speech in Light of New Pentagon Leadership


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ [$] Revisiting the MAP_SHARED_VALIDATE hack


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ [$] Revisiting PEP 394


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ [$] Revisiting PEP 394


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the Risk Management Framework in Light of Revision 2


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ 10 older Xbox games worth revisiting in 2019


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting JavaScriptCore Internals: boxed vs. unboxed


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting Software Vulnerabilities in the Boeing 787


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the abbr element


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting stable-kernel regressions [LWN.net]


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting Export Controls in the COVID Era


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting and Revising Some Tips for National Cyber Security Awareness Month


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting The Concepts of Disaster Recovery and Risk as Organizations Move Their Infrastructure To The Cloud


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ [$] Revisiting stable-kernel regressions


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting Apple Notes (6): The Protobuf


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the Office of Legal Counselโ€™s Override Opinion


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the AI diversity crisis โ€“ and how to solve it


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting the Session: The Potential for Shared Signals


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Anti-Asian Prejudice Undermines U.S. National Security: Revisiting the U.S. Governmentโ€™s Deportation of Qian Xuesen


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ ELF Section Docking: Revisiting Stageless Payload Delivery


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting 2b2t Tamed Animal Coordinate Exploit


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ AppStories, Episode 321 โ€“ Revisiting RSS


๐Ÿ“ˆ 20.94 Punkte

๐Ÿ“Œ Revisiting Android on Linux


๐Ÿ“ˆ 20.94 Punkte











matomo