Skip to content

Instantly share code, notes, and snippets.

@noidi
noidi / types.clj
Last active October 15, 2017 17:48
;; I hope this example illustrates why I think the types that Clojure
;; programmers use are hard to represent with the type systems I've seen in
;; other languages. I have only a very superficial knowledge of type theory, so
;; I may well be mixing terms or even spouting complete nonsense. Apologies in
;; advance!
;; Idiomatic Clojure code tends to use very few custom types, and instead
;; represents most data as a composition of built-in types like maps, vectors,
;; and sets. For example, instead of a Person type you might use a map like the
;; following:

Keybase proof

I hereby claim:

  • I am noidi on github.
  • I am noidi (https://keybase.io/noidi) on keybase.
  • I have a public key whose fingerprint is 8B98 202B 7E91 F525 BA56 422D 1EE1 0668 A212 782E

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am noidi on github.
  • I am noidi (https://keybase.io/noidi) on keybase.
  • I have a public key ASAL3psZL6RiuxsGF48_0997HiQ1aivKamb-sBBmHPVF6Qo

To claim this, I am signing this object:

@noidi
noidi / Rakefile
Last active September 10, 2016 10:48
file 'm_sdl.so' => 'm_sdl.c' do
sh 'gcc -shared -fpic -o m_sdl.so -Wall -Werror -std=gnu99 m_sdl.c -I/opt/gtm -O3 $(sdl2-config --cflags --libs)'
end
file 'trumps.o' => 'trumps.m' do
sh 'mumps trumps.m'
end
task :run => ['trumps.o', 'm_sdl.so'] do
sh 'env GTMXC_sdl=m_sdl.xc mumps -run trumps'
;; [09:46] < aphyr> hullo
;; [09:54] < aphyr> I'm trying to type an expression like [f g h], where (f (g (h nil))) is valid.
;; [09:55] < aphyr> e.g. something I could apply (comp) to
;; [09:55] < aphyr> But I'm having trouble figuring out how to enforce that each fn should take the next fn's output type
(ns cttest.core
(:require [clojure.core.typed :as t]))
(t/ann foo (t/All [a b c]
[[b -> c] [a -> b] [nil -> a] -> c]))
@noidi
noidi / code.clj
Last active August 29, 2015 14:05 — forked from krisajenkins/code.clj
;;; Changes:
;;; - Annotate the parameter of the lambda given to filter. This was the cause of the error.
;;; - Change the last parameter of lookup-by from Seq to Seqable to allow it to work with vectors.
;;; - Replace (IFn [a -> b]) with [a -> b]. They're equivalent.
(t/ann lookup-by (t/All [a b]
[b [a -> b] (t/Option (t/Seqable a)) -> (t/Option a)]))
(defn lookup-by
"Convenience filter. Returns the first item in coll where (= value (lookup-fn item))"
@noidi
noidi / gist:4061590
Created November 12, 2012 20:12
ClojureScript + three.js HelloWorld
(ns cljs-hello.hello
(:require-macros [cljs-hello.macros :as m]))
(defn make-world []
(let [geometry (THREE.CubeGeometry. 200 200 200)
material (THREE.MeshBasicMaterial. (js* "{color: 0xff0000,
wireframe: true}"))
mesh (THREE.Mesh. geometry material)
scene (doto (THREE.Scene.)
(.add mesh))
@noidi
noidi / gist:3751951
Created September 19, 2012 20:11
Why functional programming matters to enterprise programmers

Why functional programming matters to enterprise programmers

tl;dr: Solving a very specific problem using FP tends to produce a very general solution that's applicable to a wide range of problems.

Let's start with some Java code that we'll simplify using functional programming.

class Department {
  Employee getYoungestEmployee() {

if (employees.isEmpty()) return null;

@noidi
noidi / gist:3088247
Created July 11, 2012 05:53 — forked from sjl/gist:3088120
wat
git clone git://github.com/sjl/caves/
cd caves

Start a REPL:

lein repl

It'll grab the deps and start fine. Cool. Close out of it.

Now edit the name of one of the methods in a protocol (and all the things that use it, of course):

# HG changeset patch
# Parent cc08f20788db64c79c232265909150ee3677493a
Use the JAR from tomighty.org
diff -r cc08f20788db PKGBUILD
--- a/PKGBUILD Thu Dec 08 17:48:11 2011 +0200
+++ b/PKGBUILD Thu Dec 08 18:09:05 2011 +0200
@@ -8,10 +8,13 @@
url="http://www.tomighty.org/"
license=('Apache')