Skip to content

Instantly share code, notes, and snippets.

View cblp's full-sized avatar

Yuriy Syrovetskiy cblp

  • Montenegro
View GitHub Profile
{-# LANGUAGE TemplateHaskell #-}
module A where
import Language.Haskell.TH
makeType :: String -> DecsQ
makeType t = do
let name = mkName t
pure [DataD [] name [] Nothing [NormalC name []] []]
@cblp
cblp / .diff
Last active June 2, 2018 19:56
fizruk/snakes-demo .. Gradet/game-Snakes
diff --git a/.gitignore b/.gitignore
index cdc3c4d..82f3a88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
dist
+dist-*
cabal-dev
*.o
*.hi
@cblp
cblp / ege.cpp
Last active March 4, 2018 09:27
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/istream_range.hpp>
using namespace boost;
int main() {
@cblp
cblp / Xlsx.hs
Created February 14, 2018 09:42
-- stack --resolver=lts-10.5 script
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Rank2Types #-}
module Write where
import Codec.Xlsx
import Control.Lens
import Control.Monad.State.Strict
@cblp
cblp / curry.cpp
Last active October 20, 2017 15:48
#include <functional>
#include <iostream>
using namespace std;
using namespace std::placeholders;
template <typename A, typename B, typename C>
function<function<C(B)>(A)> curry(function<C(A, B)> f) {
return [=](A a){ return [=](B b){ return f(a, b); }; };
}
@cblp
cblp / TypeMorphMorph.hs
Last active September 12, 2017 16:56
A category of type morphisms (functors, monads, etc.)
{-# OPTIONS_GHC -Wall -Werror -Wno-orphans #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
import Prelude hiding (id, (.))
import Control.Category
import Control.Monad.Except
import Control.Monad.Trans.Maybe
@cblp
cblp / ExistentialSum.hs
Last active August 21, 2017 12:00
Example of usage of an existential type as a sum type.
#!/usr/bin/env stack
-- stack --resolver=lts-9.0 script --package=singletons
{-# OPTIONS_GHC -Wall -Werror #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
#!/usr/bin/env stack
-- stack --resolver=lts-9.0 script --package=lens --package=template-haskell
{-# OPTIONS -Wall -Werror -ddump-splices #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
true = lambda x, _: x
false = lambda _, y: y
lambda_bool = lambda b: [false, true][b]
force = lambda f: f()
enum = (
lambda start, step, stop:
force(
#include <functional>
#include <iostream>
using namespace std;
void cond(bool condition, function<void()> ifTrue, function<void()> ifFalse) {
function<void()> branches[] = {ifFalse, ifTrue};
branches[condition]();
}
template <typename T>