Skip to content

Instantly share code, notes, and snippets.

View nikita-volkov's full-sized avatar

Nikita Volkov nikita-volkov

View GitHub Profile
@nikita-volkov
nikita-volkov / sample.hs
Last active February 5, 2023 19:33
ReaderT, ExceptT, IO, composition
-- |
-- Application-wide service, which is merely a product of other services.
-- Shows how services can be de/composed and encapsulated.
module Services.Main where
import qualified Services.Db as Db
import qualified Services.Metrics as Metrics
data Env = Env {
db :: Db.Env,
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-api</artifactId>
<version>0.9.1</version>
@nikita-volkov
nikita-volkov / gist:57212aedbabeed0b5ff2
Last active September 21, 2019 22:15
Hasql Database Migration Algorithm
-- |
-- Migrate from any version to any other higher version.
migrate :: (Word, Word) -> EitherT Text (Tx s) ()
migrate =
\case
(0, 1) -> -- Execute statements, which create the DB in initial state.
(1, 2) -> -- Execute statements, which alter the DB to migrate from version 1 to 2.
(2, 3) -> -- Execute statements, which alter the DB to migrate from version 2 to 3.
(3, 4) -> throwError $ "Trying to migrate to an inexistent version"
(from, to)
@nikita-volkov
nikita-volkov / runmakeghc
Last active December 29, 2015 13:38
A script, which serves as an alternative to `runghc` (`runhaskell`), allowing it to be run with optimization modes, such as `-O2`. What it does is just compiles the passed in script to a temporary folder, runs the executable and deletes the folder afterwards.
#!/usr/bin/env runghc -w
--
-- A replacement of "runghc", which uses a compiler instead of interpreter,
-- thus allowing you to specify some important compiler flags, e.g. "-O2".
--
-- USAGE:
--
-- runmakeghc SCRIPT_PATH [COMPILER_OPTIONS] [-- SCRIPT_OPTIONS]
--
@nikita-volkov
nikita-volkov / gist:6977841
Last active July 4, 2022 13:33
Anonymous records. A solution to the problems of record-system.

#Anonymous records. A solution to the problems of record-system.

Please, beware that the proposal that follows has been implemented as a library.

The current record system is notorious for three major flaws:

  1. It does not solve the namespacing problem. I.e., you cannot have two records sharing field names in a single module. E.g., the following won't compile:

data A = A { field :: String }

import Data.List
import qualified Data.Set as Set
import Criterion.Main 
import System.Random
import Control.Applicative



main :: IO ()
@nikita-volkov
nikita-volkov / Benchmark.hs
Last active December 14, 2015 18:58
Haskell list items equality algorithms benchmark for this StackOverflow answer: http://stackoverflow.com/a/15319373/485115.
import Data.List
import qualified Data.Set as Set
import Criterion.Main
import System.Random
import Control.Applicative
import qualified Data.MultiSet as MultiSet
absDiffImpl :: (Eq a) => [a] -> [a] -> Bool
absDiffImpl a b = null $ absDiff a b
@nikita-volkov
nikita-volkov / gist:5083268
Last active December 14, 2015 11:59
A module taking the fuss of ids management away from Acid-State's IxSet

The extension module to IxSet library

{-# LANGUAGE DeriveDataTypeable, RecordWildCards, UndecidableInstances, GeneralizedNewtypeDeriving #-}
module Data.IxSet.Identified where

-- Block the standard prelude
import Prelude ()
-- Import a much more useful prelude from `classy-prelude` package
import ClassyPrelude
import Data.SafeCopy
@nikita-volkov
nikita-volkov / gist:5000556
Last active June 15, 2016 00:05 — forked from xeno-by/gist:2559714
Mixing in a trait dynamically with Scala 2.10.0. Formatted.