Skip to content

Instantly share code, notes, and snippets.

@orchid-hybrid
orchid-hybrid / numb.tcl
Created March 26, 2014 05:31
GUI to convert between hexadecimal, decimal and binary numbers
#!/usr/bin/wish
package require Tk
wm title . "numb"
grid [ttk::frame .c -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes
grid columnconfigure . 0 -weight 1
grid rowconfigure . 0 -weight 1
(require-extension shift-reset)
;; http://www.diku.dk/~andrzej/papers/RM-abstract.html
(define list-monad
(list (lambda (x)
(list x))
(lambda (m f)
(apply append (map f m)))))
#lang racket
(require scheme/control)
;; Pattern matching
(define (pattern? p e)
(cond ((null? p) (null? e))
((equal? p '_) #t)
((symbol? p) (and (symbol? e) (equal? p e)))
http://homepage.ntlworld.com/edmund.grimley-evans/bcompiler.html
Bootstrapping a simple compiler from nothing
============================================
This document describes how I implemented a tiny compiler for a toy
programming language somewhat reminiscent of C and Forth. The funny
bit is that I implemented the compiler in the language itself without
@orchid-hybrid
orchid-hybrid / Ella
Created September 19, 2014 06:48
Ella.hs
module Bee where
import Fresh
import Control.Monad.Trans
import Control.Monad.Writer
import Data.Monoid
data Op
= Add | Sub | Mul
deriving (Eq, Show)
@orchid-hybrid
orchid-hybrid / unification.eff
Created September 21, 2014 05:14
unification in Eff
type fresh = effect
operation gensym : unit -> int
end
let run s = handler
| val y -> (fun s -> y)
| s#gensym () k -> (fun s -> k s (s+1))
| finally f -> f 0;;
@orchid-hybrid
orchid-hybrid / cps.eff
Last active August 29, 2015 14:06
CPS transform using Eff
(* delimited continuations from Programming with Algebraic Effects and Handlers - Andrej Bauer, Matija Pretnar*)
type ('a, 'b) delimited = effect
operation shift : (('a -> 'b) -> 'b) -> 'a
end
let rec reset d = handler
| d#shift f k -> with reset d handle (f k)
@orchid-hybrid
orchid-hybrid / RC4.cry
Created October 27, 2014 20:27
RC4 in cryptol
swap : [256][8] -> [8] -> [8] -> [256][8]
swap s i j = [ s @ (if n == i then j else
if n == j then i else
n)
| n <- [0..255]
]
ksa_step : [inf][8] -> [8] -> [8] -> [256][8] -> ([8],[256][8])
ksa_step key i j s = (j', swap s i j')
where j' = j + s@i + key@i
@orchid-hybrid
orchid-hybrid / README.md
Last active August 29, 2015 14:08
very simple pattern match compiler
import Data.List
import Data.Ord
import Data.Bits
import Data.Char
data DInst
= Emit Char
| Backref Int Int
deriving (Eq, Show)