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
(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) |
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
;; "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: |