Skip to content

Instantly share code, notes, and snippets.

View damhiya's full-sized avatar

SoonWon Moon damhiya

View GitHub Profile
let and = fn (b1 : bool) -> fn (b2 : bool) ->
if b1 then b2 else false in
let or = fn (b1 : bool) -> fn (b2 : bool) ->
if b1 then true else b2 in
let map = fn (f : int * int * int -> int * int * int) ->
fix (mapf : list (int * int * int) -> list (int * int * int)) xs ->
case xs of
{ [] -> [] of (int * int * int)
; x :: xs -> f x :: mapf xs
} in
# Tetrahedron
# volume = 1/6
# area = (3 + sqrt 3)/2
tetrahedronMesh =
let vmap = [ 0. 1. 0. 0.
; 0. 0. 1. 0.
; 0. 0. 0. 1.
]
fmap = [ 0 0 0 1
@damhiya
damhiya / rotation.md
Last active November 25, 2023 06:18
Rotation

회전

회전에 대해 알아보자. 2차원에선 간단하지. 점 $(x,y)$$\theta$만큼 회전시킨 좌표 $(x',y')$은 이렇게 표현이 돼.

$$ \begin{pmatrix} x' \ y' \end{pmatrix} = \begin{pmatrix} \cos \theta & \sin \theta \

@damhiya
damhiya / list-nixos-profile.sh
Last active July 15, 2023 13:55
nixos profile management
#!/usr/bin/env bash
PROFILE_PATH=/nix/var/nix/profiles
get_list() {
find $PROFILE_PATH -type l \
| awk "match(\$0, /^${PROFILE_PATH//\//\\\/}\/system-([0-9]*)-link\$/, res) { print res[1] }" \
| sort
}
get_current() {
@damhiya
damhiya / flake.nix
Created April 7, 2023 08:51
xv6 dev env for nixos
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
@damhiya
damhiya / Main.hs
Created October 12, 2022 12:34
Yak shaving
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE GADTs #-}
module Main where
import GHC.Types
import Control.Monad
type Coffee = Integer
type Work = Integer
@damhiya
damhiya / Rose.hs
Last active January 31, 2022 06:14
defunctionalization
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Rose where
data Tree a = Node a [Tree a] deriving (Eq, Show)
t1 :: Tree Int
t1 = Node 1
[ Node 2
@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 ];
@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 / 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