Sila Dev Log: New Beginning in Haskell

Posted on 20th of September 2024 | 533 words

Behind the scenes, I’ve been steadily working on Sila, but some of the early design decisions – or rather, lack of design – are starting to show their limitations. So, I’ve decided to take a step back and revisit the foundation of the project. This time, though, I’m tackling it with a familiar but long-unseen tool: Haskell.

When I initially began building this compiler, I chose Common Lisp out of a personal fondness for the language. That hasn’t changed – I still love working with Lisp. However, as the project evolved, I found myself rethinking certain aspects of its structure and approach. This reflection led me to consider moving the project over to Haskell, a language I once worked with extensively but haven’t used in years.

Why the switch? Part of the motivation is purely practical, but another part is personal. Returning to Haskell after such a long break feels like dusting off an old tool that’s been sitting on the shelf for far too long. I’m eager to revisit its expressive power, and I believe Haskell’s strengths align well with the challenges and design goals I now face with this project.

While Common Lisp is wonderfully dynamic and flexible – especially when working solo – Haskell offers something I now find particularly valuable: a strong, statically-typed foundation. Haskell’s type system provides guarantees that can help me avoid some of the design pitfalls I encountered with the original Lisp implementation. Its purely functional approach also lends itself well to the sort of transformations and abstractions that compiler development requires.

Haskell’s concise and declarative nature is another major draw. Returning to the language after so many years has been a refreshing experience – its functional paradigm allows for more elegant handling of complexity, especially in areas like data structures and state management. Compared to Common Lisp’s more imperative, mutable style, Haskell’s immutability forces me to approach problems from a different angle, often leading to cleaner, more maintainable solutions.

Starting over is never easy, but it’s sometimes necessary for long-term progress. Moving to Haskell allows me to address the shortcomings of the original design in a more structured and rigorous way. With its strong type system and focus on immutability, Haskell offers a fresh perspective that I believe will result in a more robust and maintainable codebase.

Rewriting the compiler in Haskell also gives me the opportunity to dive back into a language that I’ve always admired but haven’t used in a while. This journey back to Haskell has been both challenging and exciting. As I rediscover its features, I’m reminded of why I enjoyed working with it in the first place—and why it’s the right choice for this project moving forward.

Though it may seem like a significant shift from the dynamic world of Common Lisp to the more statically-typed, functional domain of Haskell, I believe this change will ultimately lead to a better-designed compiler. With Haskell at the core, I’m confident the project will be able to grow and scale in ways that weren’t possible with the original implementation.

In the end, it feels good to dust off Haskell, and I’m excited to see how far it will take me in modernizing Sila.

Appreciation of Low Bandwidth Websites

Posted on 21st of July 2024 | 782 words

As you might’ve seen in my last post, I’ve been without an internet for good some time already. Still – like I mentioned in the last post – I’ve really enjoyed my time without it. I feel that I can switch off much better after working hours, and I still have energy to partake in various other extracurricular activities that I hold dear to my heart, like hobby programming projects, music, reading, sports and much more. So really there isn’t much to complain.

Currently, my new neighbourhood does have a pretty good signal – generally speaking. My apartment just happens to be in relatively awkward spot, which means that it’s surrounded by other buildings. I happen to have a relatively big balcony in my apartment as well and even in there I have basically one bar of connectivity going on. Naturally, inside I don’t have any signal or very little. Fortunately, I’ve been able to have just enough of connectivity so in case some emergency or something along those lines, I’m able to do something with my phone. But, when it comes to “surfing the web”, that’s not much that I can currently do.

That being said, I can do just some browsing in handful of site that don’t clog the whole bandwidth for silly updates and requests and mainly just focus on sharing good content. So I wanted to write a small appreciation post for people making websites that work with practically no internet at all.

TODO: Maybe gather some great examples of lite websites to somewhere?

Of course, when writing about this sort of topic, it also brings little bit of sadness to me to see how many websites is basically unusable without a relatively good internet. Fortunately, I live in a place where even at its worst, I can access relatively “fast” internet and of course most of the places – outside my apartment – is very well connected. I don’t need to go far from my house to get basically full 5G connectivity with varying speeds (whatever your contract at the moment happens to be). In places like Finland, 1 Gbit fiber connectivity is getting more and more normal even in somewhat rural areas. Germany is not on that level yet – and by many standards, very far from it – but it’s still good nonetheless. Something like this cannot be said about the vast majority of the countries around the world.

I kind of know the reason why something like this has happened that the significant portion of popular websites are basically unaccessible by many people. I think it’s largely due to this aggressive over-engineering software engineers tend to do in their line of work. Also, I’m not innocent in that front as well, since I’ve done my fair share of over-engineering during the years working in the industry. Sometimes since I wanted, sometimes it was needed and sometimes since I was told to.

But it begs an interesting question, why something like this so normal in our industry? Sure, there are cases where added complexity to your infrastructure, codebase, etc. has actually brought some benefits. But the amount of times that has happened is greatly outweighed by the amount of times when it, well, just has brought added complexity without any benefits. But hey! At least, the engineers feel accomplished when they are able to deliver that is “complex”.

From the UX point of view, this is also quite interesting topic, since I believe that no one in this world wants to have their app/product/software/whatever to be slow for the users. But often, this added complexity automatically hinders the performance of whatever you happen to we writing. You start doing more stuff than you would need to, this can be inform of unnecessary web requests, unnecessary computations and so on. I guess there isn’t any argument about the fact that something like this hinders the whole UX. Which begs the question? Why more people don’t care about the performance more in their products? You might have an application that might have a traditionally speaking “bad UX”, meaning maybe lots of menus, you need to press a lot of stuff to access whatever you might be after, etc. But, if everything happens instantly, I’d dare to argue it’s still pretty good UX, at least for many people. If then on the other end of the spectrum, you would have a great UX, but everything is slow and has to load lots of stuff, how good of an UX it really is at that point?

But yeah, I digress, seems that lack of internet just makes me want to write about stuff. Any case, TLDR, write light websites.

German Unefficiency and Living Without Internet

Posted on 6th of July 2024 | 1270 words

As some of you might know, I’ve been living in Berlin, Germany for a few years now. Wonderful city! Just what I was looking for couple years back when I moved here. City definitely has its flaws – like does every city in the world – but I still enjoy being here. City is definitely massive. Each district having their own life, own people and own quirks. Spectrum is wide from somewhat poshy areas of Mitte and Prenzlauer Berg to more hip and trendy areas like Neukolln and Kreuzberg to more suburban areas around the Ringbahn. Of course, since I’m mainly into various hip and trendy activities – what some might call them – most of my time has been spent lingering around and roaming the streets of eastern Berlin, mainly Neukolln and Kreuzberg since those were the districts I used to reside. Due to its sheer size, there’s no way, I’ve been able to experience all the city has to offer. Despite this, I feel that the city has offered me tremendously.

While I’ve really enjoyed living in Berlin, one thing I can’t praise at all is how things work in this country. So this is not necessarily Berlin’s fault, although, I feel its also partly due to that. But more or less everything seems to be difficult here. At least in a bureaucratic sense. Difficult in a sense that nothing really works efficiently or effortlessly, or that’s how I at least feel coming from Finland to this country. I’m not saying Finland is perfect in how country should operate, far from it. I’m just saying – using a simple and common example – that if you want to move from place to place, making this sort of address change to your government shouldn’t be too difficult. In Finland for example, if you want to move, there’s one URL that you go to, fill in your new details, and send the information. Pretty easy. In Germany, if you want to Anmeldung, you need to print your papers necessary, fill the forms, book time in your nearest Burgeramt, go there physically, just so someone can put some stamp in your papers. Sounds pretty unefficient, right? That’s because it is.

I also just recently read from the news how Germany was excited to have digitalised their medical patient information so that more stuff would happen digitally instead of manually. Making it easier to share medical history from doctor to doctor. Sounds amazing! Of course, something like this has been implemented in many different countries for 20 or so years, but hey, Germany is in no rush!

This sort of a ranty-detour gets us to the whole topic of today’s post about living without internet. So I just wanted to write some words down on how I feel after some undisclosed amount of weeks that I have been without internet at home.

This all started mainly due to the fact that I just happened to move into a new place and naturally I wanted to move my internet contract into the new address. Of course, naive and blue-eyed me thought that it would be pretty straight-forward. I just change the address, configure the router possibly in the address in case something needs to be done and that’s about it, right? Well of course not. Turns out, for some reason, there needs to be a internet technician come to your place and turn on the connection for you. Okay, sure. Interesting that it couldn’t be done remotely, but hey let’s go with it. But of course to make it not so easy, the technician isn’t able to find my home, which is interesting again since they know the address. Also, of course they could’ve just called me but that’s too much to ask I guess. So there’s an another try, but with the same result. Oh, and did I mention that there was two weeks between these attempts so it not like that they tried it again in a short period of time.

Okay, I start ranting again. Back to the topic. I wanted to jot down some thoughts that I’ve encountered while living without an internet. Turns out, I have really enjoyed my time! I’ve written in my blog about my “struggles” with for example social media and how it used to grab my attention almost wholly. But generally speaking, it feels that everything I tend to online, tends to be more on the excessive end of the spectrum. Call it excessive use of YouTube or other various places filled with endless amounts of content. I just feel that I tend to sink vast amount of hours in these sort of places, without getting much in return. While I’m not saying they are all bad, they certainly have good bits and pieces here and there, but the vast majority just feels – like someone might’ve put it already – brain-rot.

With these undisclosed amount of weeks that I’ve now been without internet, naturally, I’ve been away from all them. Even the cellural signal is quite weak in my new apartment so I haven’t been able to use them via it even that much. Fortunately, I’ve been able to keep in touch with family and friends with the little signal I’ve had at home and in case I’ve really had to use internet for something, I’ve had just to leave my home to find Wi-Fi, which also has been quite good for me, since I’ve a habit of going “monk- or hermit-mode” quite often.

I also recently changed jobs so fortunately I haven’t been in on any on-call rotation so I haven’t really had the need to work from home. Also, the new apartment has been quite close to the new office, so it hasn’t been too big of a hassle to go there daily. Even that – to my surprise – hasn’t been too bad. Why it’s to my surprise is the fact that before this I really never went to the office. This employer or the previous ones. I wouldn’t say the office that we have currently is something extra-ordinary that I would really want to spent time in there, it’s still nice, don’t get me wrong. I’ve never really just seen myself as this social butterfly who can effortlessly manage themselves mingling around in an office environment. So, I’ve always just enjoyed working from home more.

The lack of internet at home has really shown itself in my life in the form of vastly increased productivity on the stuff that I value. I’m not saying that some sort of ultimate productivity is something that everyone should strive towards – which seems to often be the case in various toxic “hustling culture” ideas – but I’m more so approaching the topic from the point of view of how much time you really can use in the stuff that brings something positive and beneficial to your life. In my case, it has shown itself in the form of increased productivity for example in exercise, making music, writing, reading and also programming passion projects. I.e. more or less most of the stuff outside personal relationships and health that I find to be important in my life.

So now I’m just spitballing with the idea of really not just getting any internet to my home. Of course, if the current job situation would allow something like that. Considering all the good effects I’ve seen in my life AND considering the fact that it would be just one less thing to worry my head in German bureaucracy, I don’t really see negative side in this.

Dump Your Currently Set Faces in Emacs

Posted on 26th of May 2024 | 639 words

Every once in a while I like to play around with Emacs themes. Of course, mainly due to yak-shaving and procrastination reasons and nothing actually valid. But it’s fun nonetheless, although occasionally very tedious. Tedious in a sense that Emacs tend to come with a lot of different faces, especially if you happen to use more than a few third-party packages.

Defining a custom theme in Emacs

Emacs comes with couple relatively straight forward way to set custom themes in the function custom-theme-set where you define the name of the theme and then the faces you want to modify:

(deftheme fancy-theme)

(custom-set-faces
 'fancy-theme
 '(default ((t (:foreground "black" :background "white"))))

 ;; [... and so on]
 )

You’re also able to control on what sort of displays your custom theme should support. For example, if you want to use theme in only terminals that support minimum number of 16 different colors, you’re able to define that like:

'(default ((((class color) (min-colors 16)) (:foreground "black" :background "white"))))

Of course that can be slightly verbose, so often you might see custom themes to be set like:

(deftheme fancy-theme)

(let ((class '((class color) (min-colors 16))))
  (custom-set-faces
   'fancy-theme
   `(default ((,class (:foreground "black" :background "white"))))

   ;; [... and so on]
   ))

But it still tedious since there is a lot of faces and there can be lot of variance between the faces so often if you want to write your own full fledged theme, it’s better to explicitly set all the faces that you plan to use. Mainly since, if the face is not set in the theme it’ll use that lastly set face for that face in question, so if you session has used multiple different faces, it can lead into some funky color combinations.

Currently in my Emacs session – which is relatively light package-wise – amount of currently set faces equals to 869.

Simple tool written for aspiring theme developers

This is why, I decided to write a simple Emacs Lisp helper function to dump all the currently set faces to a buffer where you can copy them to your own theme at will. I also made it so you can simply just dump the faces from a give package if you only care, e.g. about Magit’s faces.

(require 'cl-lib)

(defconst theme-dump--buffer-name "*theme-dump*")
(defconst theme-dump--default-format-string "%s %s ")
(defconst theme-dump--string-format-string "%s \"%s\" ")

(defun theme-dump-current-faces (pkg)
  (interactive (list (read-string "Dump faces from package (leave empty for all packages): ")))
  (let ((faces '()))
    (dolist (f (theme-dump--filter-faces-by-package pkg))
      (let ((attr-str ""))
        (dolist (a (face-all-attributes f))
          (setq attr-str
                (concat attr-str (theme-dump--format-attr-str f a))))
        (push (if (not (string-equal attr-str ""))
                  (format "`(%s ((,class (%s))))\n" f (string-trim-right attr-str))
                (format "`(%s (( )))\n" f))
              faces)))
    (let ((buf (get-buffer-create theme-dump--buffer-name)))
      (with-current-buffer buf
        (erase-buffer)
        (insert (mapconcat 'identity faces))
        (local-set-key (kbd "q") 'kill-buffer-and-window))
      (split-window-right)
      (other-window 1)
      (switch-to-buffer buf))))

(defun theme-dump--filter-faces-by-package (pkg)
  (cl-flet ((pkg-face-p (face)
              (cl-search pkg (symbol-name face))))
    (if (not (string-equal pkg ""))
        (cl-remove-if-not #'pkg-face-p (face-list))
      (face-list))))

(defun theme-dump--format-attr-str (face attr)
  (unless (equal (face-attribute face (car attr))
                 'unspecified)
    (cl-typecase (face-attribute face (car attr))
      (string (format theme-dump--string-format-string
                      (symbol-name (car attr))
                      (face-attribute face (car attr))))
      (t (format theme-dump--default-format-string
                 (symbol-name (car attr))
                 (face-attribute face (car attr)))))))

Essentially, this just gets all the faces with face-list and either returns all of the or filters them by package name if you want. Function prints the faces into a new buffer in a format that is already suitable for new custom themes:

`(magit-section-highlight ((,class (:extend t :background "grey95"))))
`(magit-section-heading ((,class (:weight bold :extend t))))
`(magit-section-secondary-heading ((,class (:weight bold :extend t))))
`(magit-section-heading-selection ((,class (:extend t :foreground "salmon4"))))
`(magit-section-child-count (( )))

;; and so on...

The printed faces can then easily be copied to custom-set-faces for your possible new theme. Faces are also backticked by default, in case you want to change faces to use variables instead of hardcoded names.

Code is in public domain and also available in sourcehut.

Dereferencing Null Pointer

Posted on 24th of May 2024 | 8 words

Bret Hart saving the day in code review.