Skip to content

Instantly share code, notes, and snippets.

View cblp's full-sized avatar

Yuriy Syrovetskiy cblp

  • Montenegro
View GitHub Profile
@cblp
cblp / abelphata.hs
Last active June 17, 2025 14:14
Simplest array CRDT
-- stack --resolver=lts-23.20 script
import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck as QC
import Test.Tasty.Runners
import Test.Tasty.SmallCheck as SC
empty :: [a]
empty = []
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template<class Variant, class... Ts>
auto match(Variant v, Ts... matchers) {
return visit(overloaded{matchers...}, v);
}
struct Human {string name; int age;};
struct Animal {string kind; int age;};
#!/usr/bin/env python3
import operator
from typing import Callable, NamedTuple, Optional, TypeVar, Generic
A = TypeVar('A')
class Lazy(Generic[A]):
@cblp
cblp / lazy_fibs.cxx
Last active September 28, 2022 18:01
#include <iostream>
using namespace std;
#define LAZY(expression) Lazy<Cons>{[=]{ return expression.get(); }}
#define LAZY_REF(expression) Lazy<Cons>{[&]{ return expression.get(); }}
template<typename T>
class Lazy {
private:
mutable shared_ptr<T> value;
#include <iostream>
#include <complex>
using namespace std;
#include <numbers>
using namespace std::numbers;
struct Expr {
virtual string source() const = 0;
virtual shared_ptr<Expr> derive() const = 0;
@cblp
cblp / derive.hs
Last active September 28, 2022 06:28
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
data Expr
= Lit Integer
| Var
| Add Expr Expr
| Mul Expr Expr
| Pow Expr Expr
| Sin Expr
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
import Control.Monad.State
data Action
= For Expr (Expr -> Action)
| Print Expr
data Expr
@cblp
cblp / Main.hs
Created July 26, 2022 11:58 — forked from Lev135/Main.hs
Debugging megaparsec transofrmer using `MonadParsecDbg` class
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- | This module contains usage example of suggested `MonadParsecDbg` type class,
-- minimized, but, I hope, demonstrative
--
-- If someone have better solution, I would like to see it
module Main where
{-# LANGUAGE MonadComprehensions #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE RebindableSyntax #-}
import Data.Set (Set, singleton)
import GHC.Exts
import Prelude
xs :: Set Int
xs = [3, 15]
@cblp
cblp / Mystudies.hs
Created February 26, 2021 21:31
recursion-schemes example
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Mystudies where
import Data.Foldable (toList)
import Data.Functor.Foldable (fold)