Skip to content

Instantly share code, notes, and snippets.

View graninas's full-sized avatar
😊
My Twitter: graninas

Alexander Granin graninas

😊
My Twitter: graninas
View GitHub Profile
@graninas
graninas / graninas_id_rsa.pub
Created March 24, 2019 12:57
My Public Key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDecJ7pnlH12W8XFJ4nGl7tZomX6esTqrzAZoTLs6ZRn8baYOKwWf57w6uSts4x0xMfVrO5YZtlBA6YSA7ysqiVLkvjCGoWbUw5goJi3kCUnQewuBy0ukobz6i/ZIEJ8vxejNggmRkQnyitBCd7nnvaCWgwDonJj4W1r77xarWvtz3QjjpGMG59i+xjuQ3Fi7sqRmwgQmBcWyo2cerA3aU4BbhmDS6tSHO2gH7I7VmII3mZX+p+0ITBGyfLgCYI85/qugR9rgK79lwEYrAuLkzxj8FArrLQWtgqfshriZRT1lBabh6dX9PWN+ArNseZVgKeycUngKclANYbl3HVfglZ
@graninas
graninas / cpp_metaprogramming_knuth_arrows.md
Last active February 17, 2019 14:14
C++ metaprogramming Knuth's arrows
@graninas
graninas / cpp_constexpr_fp.md
Last active January 26, 2019 11:22
C++ constexpr functional programming
#include <iostream>

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

constexpr int ediv (int a, int b)
{
@graninas
graninas / cpp_fp_limitations.md
Last active January 25, 2019 12:07
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
graninas / alexander-granin-bio.md
Created December 11, 2018 18:49
Alexander Granin Bio

Bio TODO

@graninas
graninas / enq-node-framework.md
Last active November 7, 2023 17:20
Building network actors with Node Framework
@graninas
graninas / cpp_stm_free_tutorial.md
Last active March 21, 2024 10:51
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
graninas / STMSample.hs
Created October 19, 2017 12:51
Dining philosophers and STM
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
@graninas
graninas / LensExample
Created June 5, 2015 16:47
Example of using lenses. Code material for presentation on Dev2Dev 2.0 (30 of May, 2015, Krasnoyarsk)
{-# LANGUAGE TemplateHaskell, Rank2Types #-}
module Main where
import Control.Lens
import Control.Monad.State
import Data.Monoid
import Data.List as L (insert, isInfixOf)