Recursively dependent types
This file contains 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 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