Skip to content

Instantly share code, notes, and snippets.

View caasi's full-sized avatar
🐫
Learning OCaml

Isaac Huang caasi

🐫
Learning OCaml
View GitHub Profile
type Option<T> = T | undefined;
type Parser<T> = (input: string) => [Option<T>, string];
const alt
: <T>(pa: Parser<T>, pb: Parser<T>) => Parser<T>
= (pa, pb) => (input) => {
const result = pa(input);
if (result[0] !== undefined) return result;
return pb(input);
};
@caasi
caasi / calcTextareaHeight.js
Created January 25, 2021 10:05
Patched Element UI input element
const HIDDEN_STYLE = `
height:0 !important;
visibility:hidden !important;
overflow:hidden !important;
position:absolute !important;
z-index:-1000 !important;
top:0 !important;
right:0 !important
`;
// 沒限制
function g(a: number[], p: (x: number) => boolean) {
let i;
for (i = 0; i < a.length; ++i) {
if (p(a[i])) return i; // early return
}
return i;
}
// 有限制
use crate::arith::syntax::*;
use Term::*;
pub fn eval1(term: Term) -> Term {
match term {
// E-IfTrue
If(box True, box t1, _) => t1,
// E-IfFalse
If(box False, _, box t2) => t2,
// E-If-Wrong
import {
Term,
tru,
fal,
cond,
succ,
pred,
isZero,
wrong,
} from '../syntax';
import React, { FC } from 'react';
import * as Inter from 'interaction';
export default const Foo: FC<Inter.ListProps<[string, number, string]>> = ({ value, onChange }) => {
return (
<Inter.List value={value} onChange={onChange}>
<Inter.Text />
<p>foobar</p>
<Inter.Number />
<Inter.Text />
@caasi
caasi / animation.ts
Last active May 12, 2020 17:16
on board presentation snippets
type Anime<T> = (time: number) => T;
const three: Anime<number> = (time) => 3;
const twice: Anime<number> = (time) => 2 * time;
const addAnime
: (ax: Anime<number>, ay: Anime<number>) => Anime<number>
= (ax, ay) => (time) => ax(time) + ay(time);
FLOL∀C 2020 邏輯、語言與計算暑期研習營
--
===================================================================
2020 Formosan Summer School on Logic, Language, and Computation
FLOL∀C '20
2020 「邏輯、語言與計算」暑期研習營
#!/usr/bin/perl
my @articles;
my $cur_article = 0;
if(@ARGV != 1){
open DIARY, "<./.note" or die;
while(<DIARY>){
exit @diary if(/EOD/);
print;
type PromiseBind<A, B> = (a: Promise<A>, f: (x: Promise<A>) => Promise<B>) => Promise<B>;
type OptionBind<A, B> = (a?: A, f: (x: A) => (B | undefined)) => (B | undefined);
type ListBind<A, B> = (a: A[], f: (x: A) => B[]) => B[];