Skip to content

Instantly share code, notes, and snippets.

@arrdem
Created October 2, 2013 16:47
Show Gist options
  • Save arrdem/6796711 to your computer and use it in GitHub Desktop.
Save arrdem/6796711 to your computer and use it in GitHub Desktop.
A toy directed graph imp'l with nonworking core.typed annotations.
(ns name.arrdem.bored.typed-graph
(:require [clojure.core.typed :as type])
(:refer-clojure :exclude [hash]))
;;------------------------------------------------------------------------------
;; Simple graph API
(def Node clojure.lang.Keyword)
(def Graph (type/Map Node (type/Seq Node)))
(def children
(type/fn> :- (type/Set Node)
[graph :- Graph
node :- Node]
(get graph node)))
(def add-node
(type/fn> :- Graph [graph :- Graph
node :- Node]
(assoc graph node #{})))
(def add-edge
(typed/fn> :- Graph [graph :- Graph
node-a :- Node
node-b :- Node]
(update-in graph [node-a]
conj node-b)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment