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
module Main where
import Control.Monad.State
import Control.Monad
import System.Random
type Name = String
data Context = Context { ctxNextId :: State Context Int
, ctxNextName :: State Context Name }
-- file PathFind/Dijkstra.hs
module PathFind.Dijkstra (findPath) where
findPath = undefined
-- file PathFind/AStar.hs
module PathFind.AStar (findPath) where
findPath = undefined
-- file PathFind.hs
module PathFind (findPath, dijkstra, aStar) where
@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)
@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 / 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 / enq-node-framework.md
Last active November 7, 2023 17:20
Building network actors with Node Framework
@graninas
graninas / alexander-granin-bio.md
Created December 11, 2018 18:49
Alexander Granin Bio

Bio TODO

@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 / 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)
{