Skip to content

Instantly share code, notes, and snippets.


Alexander Granin graninas

Block or report user

Report or block graninas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
graninas / recording.json
Last active Aug 17, 2019
Recording Sample
View recording.json
"entries": [
"tag": "Normal"
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDecJ7pnlH12W8XFJ4nGl7tZomX6esTqrzAZoTLs6ZRn8baYOKwWf57w6uSts4x0xMfVrO5YZtlBA6YSA7ysqiVLkvjCGoWbUw5goJi3kCUnQewuBy0ukobz6i/ZIEJ8vxejNggmRkQnyitBCd7nnvaCWgwDonJj4W1r77xarWvtz3QjjpGMG59i+xjuQ3Fi7sqRmwgQmBcWyo2cerA3aU4BbhmDS6tSHO2gH7I7VmII3mZX+p+0ITBGyfLgCYI85/qugR9rgK79lwEYrAuLkzxj8FArrLQWtgqfshriZRT1lBabh6dX9PWN+ArNseZVgKeycUngKclANYbl3HVfglZ
graninas /
Last active Jan 26, 2019
C++ constexpr functional programming
#include <iostream>

constexpr int sum (int a, int b)
	return a + b;

constexpr int ediv (int a, int b)
graninas /
Last active Jan 25, 2019
C++ FP Limitations

Weak type deduction

auto, lambdas -> std::function

auto m1 = newTVar(10);                                                // ok
auto m2 = stm::bind<TVarInt, TVarInt>(m1, [](const auto& tvar)        // ok, full bind type specified
    auto mm1 = writeTVar(tvar, 20);
    return sequence(mm1, pure(tvar));
graninas /
Last active Nov 7, 2019
Software Transactional Memory in C++: Pure Functional Approach (tutorial)

Software Transactional Memory in C++: pure functional approach (Tutorial)

In this article I’ll tell you about my pure functional library for Software Transactional Memory (STM) that I’ve built in C++. I adopted some advanced functional programming concepts that make it composable and convenient to use. Its implementation is rather small and robust, which differentiates the library from competitors. Let’s discuss what STM is and how to use it.

graninas / STMSample.hs
Created Oct 19, 2017
Dining philosophers and STM
View STMSample.hs
takeFork :: TVar Fork -> STM ()
takeFork tvFork = do
fork <- readTVar tvFork
case fork of
InUse -> retry
Free -> writeTVar tvFork InUse
makeDiningPhilosopher :: TVar Fork -> TVar Fork -> STM (TVar Philosopher)
makeDiningPhilosopher leftFork rightFork = do
takeFork leftFork
You can’t perform that action at this time.