This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; -*- 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 '() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(datatype whisky | |
if (element? X [bourbon scotch]) | |
________________________________ | |
X : whisky;) | |
(datatype beer | |
if (element? X [lager stout]) | |
______________________________ | |
X : beer;) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
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 #-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Text.Parsec | |
testString = unlines [ | |
"foo {", | |
" contents of foo", | |
" a stray }", | |
"}", | |
"bar {", | |
"}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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)) |