Skip to content

Instantly share code, notes, and snippets.

@JulianBirch
Created September 23, 2013 20:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JulianBirch/6676514 to your computer and use it in GitHub Desktop.
Recursively dependent types
(ns sprang
(:require [clojure.core.typed :refer :all]))
(declare-protocols IValidator)
(ann-record ValidationError [validator :- IValidator
value :- Any])
(defrecord ValidationError [validator value])
; TODO: Figure out how to make occurrence typing type :errors
(ann-record ValidationResult
[status :- (U ':ok ':error)
result :- Any
errors :- (U nil (ISeq ValidationError))
input :- Any])
(defrecord ValidationResult [status result errors input])
(ann-protocol IValidator
validate- [IValidator Any -> ValidationResult])
(defprotocol> IValidator
"Validator abstraction"
(validate- [this value] "Evaluates the validator."))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment