Skip to content

Instantly share code, notes, and snippets.

View damhiya's full-sized avatar

SoonWon Moon damhiya

View GitHub Profile
@damhiya
damhiya / Automaton.hs
Created December 31, 2020 07:06
Powerset construction algorithm (NFA to DFA conversion)
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Automaton where
import Data.Maybe
import Data.Map as M
import Data.Set as S
import Data.IntMap as IM
import Data.IntSet as IS
@damhiya
damhiya / configuration.nix
Last active April 4, 2021 10:06
kime for nix
let
kime = import ./pkgs/kime.nix;
gtk3_cache = pkgs.runCommand "gtk3-immodule.cache"
{ preferLocalBuild = true;
allowSubstitutes = false;
buildInputs = [ pkgs.gtk3 kime ];
}
''
mkdir -p $out/etc/gtk-3.0/
GTK_PATH=${kime}/lib/gtk-3.0/ gtk-query-immodules-3.0 > $out/etc/gtk-3.0/immodules.cache
@damhiya
damhiya / Powf.hs
Created January 25, 2021 17:02
apply function n times in haskell
import Data.Monoid
import Data.Functor.Const
powf :: (a -> a) -> Int -> a -> a
powf f n = (appEndo . getConst . replicateM_ n . Const . Endo) f
@damhiya
damhiya / Sort.hs
Last active February 10, 2021 08:01
haskell merge sort using ST monad
module Sort where
import Control.Monad.ST
import Data.Vector as V
import Data.Vector.Mutable as MV
sort :: Ord a => Vector a -> Vector a
sort v =
if V.length v <= 1 then
v
@damhiya
damhiya / DNEtoEM.hs
Created February 18, 2021 20:06
double negation elimination -> law of excluded middle (point-free)
{-# LANGUAGE RankNTypes #-}
module DNEtoEM where
data Bottom
type Not a = a -> Bottom
type DNE = forall a. Not (Not a) -> a
type EM = forall a. Either a (Not a)
@damhiya
damhiya / fft.cpp
Created February 23, 2021 14:10
c++ fft
#include <iostream>
#include <vector>
#include <complex>
#include <cmath>
#include <cstdint>
#include <immintrin.h>
const uint8_t flip_nibble[16] = {
0, 8, 4, 12,
@damhiya
damhiya / Replicate2.hs
Created February 25, 2021 07:45
haskell laziness
replicate2 :: Int -> a -> a -> [a]
replicate2 n x y = as where
(as, bs) = go n bs []
go 0 as bs = (as, bs)
go n as bs = go (n-1) (x:as) (y:bs)
@damhiya
damhiya / Fibonacci.hs
Created March 2, 2021 07:33
initial algebra
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE LambdaCase #-}
module Fibonacci where
@damhiya
damhiya / NAry.hs
Last active March 20, 2021 04:06
NAry.hs
fmap2 :: (Functor f1, Functor f2) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)
fmap2 = fmap . fmap
for :: Functor f => f a -> (a -> b) -> f b
for = flip fmap
infixr $:
($:) :: (Functor f, Functor g) => f (g a) -> (a -> b) -> f (g b)
($:) = flip fmap2
@damhiya
damhiya / coq-menhirlib.nix
Created January 6, 2022 15:18
nix coq environment
{ stdenv, coq }:
stdenv.mkDerivation {
pname = "coq${coq.coq-version}-coq-menhirlib";
version = "20211125";
src = builtins.fetchTarball {
url = "https://gitlab.inria.fr/fpottier/menhir/-/archive/20211125/archive.tar.gz";
sha256 = "0ls13myx5g4d32rq5prnikql0wvsrisll88xhbwi3w9v13lwnal0";
};
buildInputs = [ coq ];