Skip to content

Instantly share code, notes, and snippets.

@Azel4231
Azel4231 / core.clj
Last active September 16, 2022 13:31
Using multimethod hierarchies with spec
(ns applesoranges.core
(:require [clojure.spec.alpha :as s]))
;; define the properties
(s/def ::fruit-attribute-spec (s/keys :req [::diameter ::color]))
(s/def ::diameter nat-int?)
(s/def ::color #{:green :orange})
;; define the "type"-hierarchy
;; seemed like a good idea to use a separate spec for the hierarchy (in order to keep things simple)
@Azel4231
Azel4231 / intro.clj
Last active May 11, 2020 19:24
Dependent types with clojure.spec (requires clojure-1.9alpha16+)
;; "Can you model dependent types in clojure.spec?"
;; What are dependent types?
;; -> Parts of the data depend on each other
;; -> The structure of the data depends on certain values in the data itself
[3 "A" "B" "C"]
;; [count & elements]
;; Valid: