Hi folks,
It seems no matter what language I work in professionally I seem to always take Elm along for the ride in one way or another. Now it’s Go’s turn!
For the last year I have been working on a really interesting Go project in the Fin-Tech world. Go is a wonderful language to learn, very small, very fast and quite easy to pick up.
Whilst i love writing Go, I really was missing a lot of the functional programming ‘Elmish’ ways I am used to when solving problems. It’s second nature to think about a problem and imagine in my head how I would solve that with Elm. I deeply wanted that comfort when working on this client project.
It started with Dict
and then things escalated really quickly and before i knew it I had Basics
, List
, Set
, Maybe
etc etc. Pretty much all of elm/core is there minus the packages that don’t quite make sense outside the elm runtime like Task
, Platform
, Process
, and Debug
.
The package is called scion-tools and there a lot of missing functions as I just implemented what I needed and you can see those in the issues. I’m frequently adding more all the time, currently working on the Array
implementation.
Simple example
Let’s face it, Go is not Elm, but I get a huge amount of satisfaction only needing to think about how I would solve something just by relying on my Elm experience and knowledge.
-- List
Foldl(Cons,Empty[int](), [1,2,3]) -- [3,2,1]
-- Dict
Get(1, Singleton(1, "one")) -- Just "one"
-- String
DropLeft(2,"The Lone Gunmen") -- "e Lone Gunmen"
You get the idea.
Implementation differences
Dict
is really the only slightly different implementation I did. As Elm balances the Red-Black tree, it does a pass from the bottom of the tree to the root and ‘potentially’ sorts nodes on the way up. This allows it to maintain structural equality between trees. My implementation, whilst completely immutable, only does in placement balancing as it walks the tree a bit like the GIF below. So everything works the same, but it’s not technically structurally equal between trees.
So if you use Go and want some comforts from home feel free to check it out. Also, if you want a taste of Go there are a heap of low hanging fruit functions to implement in case you’re feeling ‘contributee’.
Thanks!