This file contains 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
enum Pair<T, WORLD> { | |
case cons (T, WORLD) // (value, outside) | |
} | |
// Outside the computer | |
typealias WORLD = Any | |
// IO Monad Instance (a.k.a IO Action) | |
typealias IO<T> = (WORLD) -> Pair<T, WORLD> |
This file contains 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
(ns sunil.curry) | |
(defn partial+ | |
"Takes a function f and fewer than the normal arguments to f, and | |
returns a fn that takes a variable number of additional args. When | |
called, the returned function calls f with args + additional args. | |
differs from the core version in that it works on just one argument." | |
{:added "1.0"} | |
([f] f) | |
([f arg1] |
This file contains 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
(defmacro def-curry-fn [name args & body] | |
{:pre [(not-any? #{'&} args)]} | |
(if (empty? args) | |
`(defn ~name ~args ~@body) | |
(let [rec-funcs (reduce (fn [l v] | |
`(letfn [(helper# | |
([] helper#) | |
([x#] (let [~v x#] ~l)) | |
([x# & rest#] (let [~v x#] | |
(apply (helper# x#) rest#))))] |