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 / 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)
{
@graninas
graninas / cpp_metaprogramming_knuth_arrows.md
Last active February 17, 2019 14:14
C++ metaprogramming Knuth's arrows
@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 / recording.json
Last active August 17, 2019 15:11
Recording Sample
{
"entries": [
[
0,
{
"tag": "Normal"
},
"GenerateGUIDEntry",
"{\"contents\":{\"guid\":\"662ed4a1-950b-48cd-a91d-1091342070d9\"},\"tag\":\"GenerateGUIDEntry\"}"
],