This is an honest question, not a a troll. I'm asking for your patience.
When Cedric talks about dependent types, the benefit he states is checking List lengths at compile time:
Having a list with one element would be a type error, so the second line in the snippet above should not compile.
When Ana Bove and Peter Dybjer talk about dependent types, the benefit they state is checking list lengths at compile time:
Dependent types are types that depend on elements of other types. An example is the type An of vectors of length n with components of type A. Another example is the type Amn of m n-matrices. We say that the type An depends on the number n, or that An is a family of types indexed by the number n.
The larger point being we have additional guarantees about the correctness of our program because of additional information and checks at Compile time.
Now my experience is that people (from a Haskell background) sneer at Lisp because it is a 'dynamic language'. Where they're coming from is that it looks unsound because of how it compares to the rich Haskell type system. (I hold nothing against them - I think it is very interesting).
The point is they claim that Haskell (or Agda etc) has additional information at compile time that is not available to a dynamic language like Lisp. (I'm going to use Lisp as the 'family of languages' and assume that Clojure is a Lisp).
Now I can do the following in Clojure to check the length of an array at compile time:
(def my-vec-of-length-2 [0 1])
(defmacro compile-time-vec-length-check [x n]
(let [x @(resolve x)]
(assert (= n (count x)))))
(compile-time-vec-length-check my-vec-of-length-2 3)
Now this will fail, because I'm expecting a vector of length 3, but the underlying vector is of length 2. I got this information at Compile Time.
user$ lein uberjar
Compiling compile-time-vec-check.core
Exception in thread "main" java.lang.AssertionError: Assert failed: (= n (count x))
Now I seem to be getting the benefits of Dependent Typing in a 'dynamic language'.
My question is Is it possible to realize the benefits of dependent typing using macros in Lisp?