Skip to content

Instantly share code, notes, and snippets.

@deech
deech / EmacsConfig
Created November 23, 2016 22:13
Emacs Config
;; -*- mode: dotspacemacs -*-
;; This file is loaded y Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration."
(setq-default
;; List of additional paths where to look for configuration layers.
;; Paths must have a trailing slash (ie. `~/.mycontribs/')
dotspacemacs-configuration-layer-path '()
@deech
deech / union.shen
Created November 1, 2016 01:34
Shen Union type
(datatype whisky
if (element? X [bourbon scotch])
________________________________
X : whisky;)
(datatype beer
if (element? X [lager stout])
______________________________
X : beer;)
Most remember Pieter Hintjens for his messaging protocols. I don't know anything about that,
but I credit him with rekindling my love of programming in general, Lisp and functional programming
in one fell swoop about 17 years ago.
He did this by writing 'Libero', a mid-90's C program that took an ASCII diagram of a state machine
and produced code that ran that machine in a remarkable number of languages including 'sh', 'python',
'C' and many more. Some of them are listed on the original page (https://imatix-legacy.github.io/libero/).
I discovered in the early 00's and it fascinated me because was a unique combination of code generation
and what is now called purely functional programming.
@deech
deech / liftM2Equivalent.hs
Created July 2, 2016 17:52
liftM2 equivalent
monadic = do
x <- [0,1]
y <- [0,2]
return (x + y)
applicative = (+) <$> [0,1] <*> [0,2]
comprehension = [(x + y) | x <- [0,1], y <- [0,2] ]
main = do
print monadic
print applicative
print comprehension
(define string-concat
{ (list string) --> string }
[] -> ""
[S] -> S
[S | Ss] -> (@s S " " (string-concat Ss)))
(datatype verified-types-for-lists
_______________________________________
(empty? Xs) : verified >> Xs : (list A);
@deech
deech / nset.el
Created March 5, 2016 00:27
Setting an element in a nested list structure
(defun nset-element-at (path ast new-element)
(if (= 0 (length path))
(setf ast new-element)
(let ((place-fn)
(path (reverse path)))
(progn
(dotimes (current-index (length path) nil)
(setq place-fn
(if (= current-index 0)
(list 'nth (nth current-index path) 'ast)
@deech
deech / TypeFamily.hs
Created January 8, 2016 15:28
Searching a type level list using typeclasses vs. closed type families.
{-
This code shows how to check if a type-level list contains a given type.
It first shows the approach required for older versions of GHC (< 7.6.x)
and then a version using closed type families supported in GHC 7.8.1 and greater.
-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
@deech
deech / NonGreedy.hs
Created June 26, 2015 00:26
Non Greedy Parsing
import Control.Monad
import Text.Parsec
testString = unlines [
"foo {",
" contents of foo",
" a stray }",
"}",
"bar {",
"}"
@deech
deech / TypeLevelDebugger.hs
Created May 4, 2015 21:41
Type Level Debugger
{-# LANGUAGE GADTs, UndecidableInstances, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, FlexibleContexts, ScopedTypeVariables, OverlappingInstances, EmptyDataDecls #-}
data A a
data B a
data C a
data D a
data E a
data F a
type AToF =
;; Neat way of getting all Emacs functionality in Evil's insert mode
(defun with-evil-mode (mode key-behavior-pairs)
(mapcar #'(lambda (pair)
(define-key
mode
(car pair)
(cdr pair)))
key-behavior-pairs))