Skip to content

Instantly share code, notes, and snippets.

@myuon
myuon / CAM.ml
Created October 19, 2016 16:47
Cousineau G., Curien P.-L., Mauny M. The categorical abstract machine. — LNCS, 201, Functional programming languages computer architecture.-- 1985, pp.~50-64.
type expr =
| MLplus | MLequal | MLfst | MLsnd
| MLint of int
| MLbool of bool
| MLvar of string
| MLcond of expr * expr * expr
| MLpair of expr * expr
| MLin of dec * expr
| MLabstr of pat * expr
| MLapp of expr * expr
@myuon
myuon / lens-cheatsheet.md
Created April 6, 2014 06:41
Lens CheatSheet
package golangglobalcachewithmutex
import "sync"
type MemCache[K comparable, T any] struct {
cache map[K]T
mutex *sync.Mutex
}
func (m MemCache[K, T]) Get(key K) (T, bool) {
@myuon
myuon / search.hs
Last active April 26, 2023 02:39
2つの異なる平方数の和として3通り以上の仕方で表されるような奇数はどのようなものが存在するか?
sqRootPair :: Int -> [(Int, Int)]
sqRootPair n = filter (\(x,y) -> x^2 + y^2 == n)
[(x,y) | x <- [1..n], y <- [1..n], x < y, x^2 < n, y^2 < n]
show' :: [(Int, Int)] -> String
show' ns = ((\(x,y) -> show $ x^2 + y^2) $ ns !! 0) ++ " :" ++ show ns
main = do
mapM_ (putStrLn . show') $ filter (\x -> length x /= 0) [sqRootPair n | n <- [1,3..]]
@myuon
myuon / CR.thy
Last active April 9, 2023 08:11
CR from scratch
theory CR
imports "~~/src/HOL/Nominal/Nominal"
begin
atom_decl var
nominal_datatype lambda =
Var var
| App lambda lambda (infixl "$" 120)
| Abs "«var»lambda" ("lam [_]._" [100,100] 100)
@myuon
myuon / Category3.thy
Last active March 23, 2023 11:55
Yoneda Lemma
definition (in Category) Iso where
"Iso f g ≡ (f ∘ g ≈ id (dom g)) & (g ∘ f ≈ id (dom f))"
definition Iso_on_objects ("_ [ _ ≅ _ ]" 40) where
"𝒞 [ A ≅ B ] ≡ (∃f∈Arr 𝒞. ∃g∈Arr 𝒞. f ∈ Hom[𝒞][A,B] & g ∈ Hom[𝒞][B,A] & Category.Iso 𝒞 f g)"
record 'c setmap =
setdom :: "'c set"
setcod :: "'c set"
setfunction :: "'c ⇒ 'c"
use std::collections::HashMap;
fn parse_string(chars: &[char]) -> (String, &[char]) {
if chars[0] != '"' {
unreachable!()
}
let mut result = vec![];
let mut index = 1;
import React, { useState, useCallback, MouseEvent } from "react";
import { css } from "@emotion/core";
const RippleEffect = ({
top,
left,
radius,
opacity,
transition,
scale,
/** @jsx jsx */
import React from "react";
import { jsx, css } from "@emotion/core";
export const GamingTextField: React.FC = () => {
return (
<div
css={css`
background: linear-gradient(
217deg,
@myuon
myuon / DP.ts
Last active January 31, 2020 14:04
type D<T> = {
[P in keyof T]?: T[P] extends Array<infer U> ? Array<D<U>> : T[P]
}
type W<V> = {
wrapper: V
}
type A = D<{
hoge: number,