Skip to content

Instantly share code, notes, and snippets.

View ckoparkar's full-sized avatar

Chaitanya Koparkar ckoparkar

  • Indiana University
  • Bloomington, IN
View GitHub Profile
@ckoparkar
ckoparkar / Tree.hs
Last active January 27, 2018 03:10
module Tree where
data Tree = Leaf Int | Node Int Tree Tree
deriving (Show, Read, Eq, Ord)
type Forest = [Tree]
mkTree :: Int -> Tree
mkTree n =
case n of
@ckoparkar
ckoparkar / see_also.clj
Last active January 20, 2018 22:40
Extract see-also information from ClojureDocs
;; depends on monger
;; [com.novemberain/monger "3.1.0"]
(ns cider.nrepl.middleware.see-also
(:require [monger.core :as mg]
[monger.collection :as c]))
(defn extract-see-alsos
[]
(let [conn (mg/connect)
To get around this, we have to prove that this recursion is "welll-founded". Consider the example of `<` and `<=`. The
relation `<` is well-founded but `<=` is not. Because in `a < b < c`, we know that `a` is strictly less than `b`. This is
finite and terminating. Whereas we can make infinite chains of `a <= a <= a ...`. This is called "accessibility". Using this
concept, we have to prove that our `power` function is well-founded. I cannot fully explain this here; I am still working on
understanding it completely. But this talk by Eric Mertens, https://vimeo.com/36519234 is really great. And here's a similar
implementation in Idris, https://github.com/idris-lang/Idris dev/blob/0d3d2d66796b172e9933360aee51993a4abc624d/libs/contrib/Data/Nat/DivMod/IteratedSubtraction.idr.
@ckoparkar
ckoparkar / valof.rkt
Last active December 11, 2016 19:47
Racket interpreter
(define unops '(sub1 zero? car cdr))
(define binops '(* + > >= < <= = cons))
(define empty-env
(lambda ()
'(empty-env)))
(define extend-env
(lambda (var val env)
`(extend-env ,var ,val ,env)))
data Parity : ℕ -> Set where
even : (k : ℕ) -> Parity (k * 2)
odd : (k : ℕ) -> Parity (1 + k * 2)
parity : (n : ℕ) -> Parity n
parity zero = even zero
parity (succ n) with parity n
parity (succ .(k * 2)) | even k = odd k
parity (succ .(1 + k * 2)) | odd k = even (succ k)
@ckoparkar
ckoparkar / idris-typechecker.log
Created August 19, 2016 16:31
Log output from idris-log buffer in Emacs
Elaborating Main.SplitView
Cryptol.idr:83:6
Main.SplitView pre-type {n : Nat} ->
(m : Nat) ->
Vect (mult m
n)
a ->
Type[]
Main.SplitView type []
{a : _} ->
@ckoparkar
ckoparkar / Tree.elm
Last active September 7, 2017 05:08
Implementation of Binary Search Tree in Elm
{-----------------------------------------------------------------
A "Tree" represents a binary tree. A "Node" in a binary tree
always has two children. A tree can also be "Empty". Below I have
defined "Tree" and a number of useful functions.
This example also includes some challenge problems :)
-----------------------------------------------------------------}
@ckoparkar
ckoparkar / rust.md
Last active November 12, 2015 09:43
Integrate rustfmt with emacs.
@ckoparkar
ckoparkar / server.json
Created October 27, 2015 13:49
consul single server config
{
"bootstrap": true,
"server": true,
"datacenter": "con",
"data_dir": "/tmp/consul",
"encrypt": "yJqVBxe12ZfE3z+4QSk8qA==",
"log_level": "INFO",
"enable_syslog": true,
"ui_dir": "~/consul_config/dist",
"acl_datacenter": "con",
#!/usr/bin/env bash
# Save and restore the state of tmux sessions and windows.
# TODO: persist and restore the state & position of panes.
set -e
dump() {
local d=$'\t'
tmux list-windows -a -F "#S${d}#W${d}#{pane_current_path}"
}