Lab notes

Lab notes ab notes
  • Advantage and disadvantage

    January 7, 2024

    Let’s talk Dungeons & Dragons! I’ve been spending a bit of time with Baldur’s Gate 3, rolling dice, passing and failing checks. Usually, to do an ability check you roll a 20-sided die (d20), compare what you rolled with a difficulty class (DC) of the check, and if it’s greater than or equal to the DC — you succeed the check, otherwise you fail.

    Die roll

    But what if you roll the die two times and then pick either the higher or the lower number? This is called respectively an advantage and disadvantage in D&D. It feels that the effects of advantage and disadvantage on the chance of success should be similar. Yet, it couldn’t be further from the truth!

    …continue reading…

  • When 1 is 2 and 8 turns into 24

    July 30, 2023

    How complicated can numbers really be? In OCaml, turns out, quite a bit: sometimes ‘1’ turns up as ‘2’ in the assembly or a 64 bit number suddenly takes up 192 bits of space. But is it necessarily a bad thing?

    …continue reading…

  • Getting a Global Talent visa in the UK

    March 12, 2023

    A few days ago I received a Global Talent UK visa as an Exception Talent in the field of Digital Technology. This would make a great #humblebrag post, but with everything happening now in Tech (and in the world, really), I want to help raise awareness about the Global Talent visa scheme and share some quick notes about my experience that some of you may find useful.

    …continue reading…

  • Writing a compiler in F# (video series)

    September 12, 2022

    In this 5 part series I build a compiler for a small functional language called Fang. The series is focused on implementing a compiler backend for a functional language which is a variation of the untyped λ-calculus. Each video demostrates a complete implementation of a particular part of the compiler: from the abstract syntax tree to different evaluation strategies, to the bytecode and the virtual machine.

    …continue reading…

  • du it in Rust: async, tokio, streams, and surprises about perf

    April 12, 2021

    “Rewrite it in Rust!” really picked up some steam and for a good reason: you get safety, expressiveness… and often better performance too. One such project is a rewrite of GNU coreutils in Rust. coreutils has been developed and improved over many years, so it’d be interesting to see where the rewrite will land performance-wise.

    In the meantime, I decided to take the venerable du utility and re-implement it in Rust. Moreover, I wanted to take full advantage of Rust’s “fearless concurrency” and use async and tokio to extract more performance in a multi-core environment.

    …continue reading…

  • What's new in Scala 3

    February 8, 2021

    This is a two-part discussion with Anton Sviridov (at the time a Staff Engineer @ Disney Streaming) about various new features and quality of life improvements in Scala 3.

    In Part 1 we talk about various “standalone” features like enums, opaque types, significant indentation, etc. And to be honest this was already enough to get me excited about the language again.

    …continue reading…

  • Benchmarking in Haskell (with a guest appearance from Rust)

    December 6, 2020

    Last time we implemented 2 different solutions for a coding interview problem: one that uses Data.Map and another one with MArray and ST. This time we’ll benchmark those solution (and the one guest solution) and see how they compare to each other and to yet another solution written in Rust.

    …continue reading…

  • Coding interview in Haskell (FAANG-style). Yay or nay?

    November 23, 2020

    Can Haskell be a practical language choice for passing a FAANG-style coding interview? To find this out we’re going to solve a typical interview problem in Haskell in 2 different ways:

    • simple with recursion and persistent maps, and
    • more advanced with mutable arrays and ST monad.

    In both cases we’re going to look at how straightforward the translation from the original idea to the code is.

    …continue reading…

  • System calls at the assembly level

    October 26, 2020

    We’re going to take a quick look at the system calls (in a Linux-centric way) and answer the following questions:

    • what syscalls are,
    • motivation behind syscalls,
    • slow and fast syscall mechanisms.

    We’ll be using assembly to see what’s happening at the lowest level and will browse Linux kernel source code to find answers to some important questions we’ll have along the way.

    …continue reading…

  • (╯°□°)╯ ¬¬(A∨¬A)

    April 26, 2019

    … or “the missing Law of Excluded Middle”.

    First things first, Law of Excluded Middle or LEM is an axiom of logic that states that either some proposition A holds or its negation ¬A holds, there is no third choice. LEM is one of the core tenets of formal reasoning in “classical” branches of mathematics, and for me as a classically trained mathematician this is indeed a very natural way of thinking.

    Recently, I got interested in the theory of programming languages. The discipline differs a great deal from functional analysis, probability theory or other familiar branches of mathematics, and learning required starting from the very basics, including proof theory and intuitionistic logic.

    Honestly, this all did feel pretty daunting and unproductive given how much effort was required even for simple proofs. So I figured that doing exercises in code instead of pencil & paper should make it more fun.

    Ahead are some basic pieces of intuitionistic logic accompanied by snippets of Coq code.

    …continue reading…

  • Assembling FizzBuzz

    January 16, 2019

    The previous post covers preliminary topics that include tool-chain, compiling assembly programs and turning them into executables, a bit about anatomy of Mach-O object files, and finally SysV ABI and system calls.

    With that out of the way, we are ready to get serious and solve some real problems… like FizzBuzz. This time around we’ll be doing dynamic linking with C runtime, using library functions, accessing command line arguments, and, of course, fighting segfaults.

    This is not a post about how to solve a FizzBuzz. The problems is used merely as a means to illustrate low-level aspects of linking, executable loading, lazy symbol binding, etc.

    …continue reading…

  • Assembling a no-op

    December 31, 2018

    When I hear hello-world I imagine a trivial one-line program. However, things that are actually happening under the hood are far from being trivial: memory allocation, register and stack manipulation, and interop with an OS kernel among others. So I figured that going a couple layers down the stack to the bare assembly in order to build a minimal working program (and a couple more complex ones) might be a fun excercise.

    This is the first post about assembly on MacOS X, that covers “getting started”, calling conventions and system calls. I plan to write another post with more practical examples later on.

    …continue reading…

  • What a Functor is anyway?

    October 2, 2017

    A functor is a homomorphism of categories. Nice and short definition, but it made absolutely no sense to me. At the time I decided to step up my FP game, I was pretty well versed in Scalaz, confidently used Functor, Monad, Applicative and the like. So, I jumped into a textbook on Category Theory… and got totally stuck. Something just hadn’t clicked in my mind, I couldn’t map the math to Scalaz code, and instead of being enlightened I only got confused. Then other things came up, and Cats were put on a back-burner. The issue as I see it now was in the wrong mindset I developed while being exposed only to the code and internet articles. Recently, I made another attempt in learning Category Theory which is on-going now and to some extent more successful.

    …continue reading…