Skip to content

Instantly share code, notes, and snippets.

View wweic's full-sized avatar
😀
Hacking

Wei Chen wweic

😀
Hacking
View GitHub Profile
@wweic
wweic / weirg_go.go
Created January 26, 2014 02:44
weird-go.go
package main
import (
"fmt"
)
func a ()[]int {
var arr [16]int
for i := range arr {
arr[i] = i
@wweic
wweic / weird-ml.ml
Created January 1, 2014 16:09
OCaml typing weirdness
type atype = {a : int}
type btype = {a : int; b : int}
let accept {a = x} = x
(*
---> val accept : btype -> int = <fun>
select the last record type which contains the fields
*)
;; A Scheme-to-C compiler.
;; Author: Matthew Might
;; Site: http://matt.might.net/
;; http://www.ucombinator.org/
;; The purpose of this compiler is to demonstrate
;; the most direct possible mapping of Scheme into C.
;; Toward that end, the compiler uses only two
;; intermediate transformations: mutable-variable
@wweic
wweic / ycomb.rkt
Created August 19, 2013 04:13
A simple Y-combinator deduction.
#lang racket
; a simple example to deduce Y-combinator for factorial function
; author: Wei Chen([email protected])
; 1.
; we can use lambda extraction to get reference to self
(define f1
(lambda (fac)
(lambda (x)
@wweic
wweic / reg_parser.ml
Created August 1, 2013 03:05
Parse regular expression pattern. using recursive descent.
(* Parse a subset of regular expression, using recursive descent *)
(* modified from https://code.google.com/p/sharable-stuff/ *)
type regexp =
| Empty_String
| Char of char
| Union of regexp * regexp
| Concat of regexp * regexp
| Star of regexp
@wweic
wweic / lambda.ss
Created October 31, 2012 12:38
notes of chapter 9 of "The little schemer"
#lang scheme
;; notes about Y combinator and related.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; function never stop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define eternity
(lambda (x)
(eternity x)))
@wweic
wweic / code_contest_template.cpp
Created October 9, 2012 07:34
Code template for programming contest
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>