Is anyone adding clojure.spec to Elixir?

clojure.spec ( seems like a very nice bit of technology. It has been ported to Haskell and Scala, so an Elixir version should certainly be possible. Is anyone working on doing this?


1 Like

Not that I’m aware of, but I’d certainly love to have something like it on Elixir, will see if this weekend I can build an small prototype to gather feedback.

Can you elaborate a bit on what this is? The linked to page while thorough buries the lead a bit.


The page goes on for a bit, but then it’s a big topic with a lot of detail. If you have the time, I’d suggest watching Stuart Halloway’s video: “Agility & Robustness: Clojure spec” (

clojure.spec aims to provide a standard, expressive, powerful and integrated system for specification and testing. It does this by providing a composable, declarative framework for describing data structures, functions, and more.

The basic idea is that specs are nothing more than a logical composition of predicates. Specs for map keysets provide for the specification of required and optional key sets. Specs for sequences/vectors use a set of standard regular expression operators, with the standard semantics of regular expressions.


For quicker introductions on the topic, I really like Carin Meier’s post on the topic and a short video introduction also from Stuart. Carin has other blog posts and you can also find more clojure.spec videos in the channel.


I also found Rich Hickey’s June 7 Cognicast ( to be interesting and informative. One of the remarks that Rich makes is that “all code is data, but all data is not code”. In terms of making spec play nicely with Elixir (etc), this begs some questions about how spec’s syntax could be adapted to fit in to the BEAM ecosystem.

Rich and Stuart note that spec can solve a number of problems in a variety of contexts. In the BEAM, I could imagine spec being used to validate messages, providing detailed analysis of problems. This seems to fill a rather large hole in our current infrastructure.

1 Like

Not to be argumentative but the fact that it’s ported to Haskell and Scala (both strongly typed languages) doesn’t lead to “therefore it should be easy to port to Elixir”

I said nothing about “easy”; rather, I said “possible”. In any event, I was referring to the fact that both of those languages use algebraic (rather than Lispish) syntax. Finally, all of the languages in question are strongly typed, but only some of them are statically typed.

That said, making such a port work well for Elixir is far above my pay grade. I leave that to José Valim, Chris McCord, et al.


Fair point. I did say “easy” and you did say “possible”. And yes that is quite a difference. And yes you’re correct; I should have said statically typed in reference to Haskell and Scala. Either way, I would say there are some significant differences between Haskell and Scala and Elixir at least in terms of the type system if nothing else.

Clojure as Elixr can be put in the same bag of dynamic type languages. I think clojure.spec is something like Elixr @spec with Dialyzer (maybe more advance )

Writing a spec should enable automatic:

Error reporting
Test-data generation
Generative test generation


I don’t agree that clojure.spec was ported to Scala, Haskell as these languages are static typed opposite to Elixir, Clojure which are dynamic languages.
This is totally different approach adding specification to dynamic languages (like typescript for javascript) vs build in types to static languages.

1 Like

This is in many respects orthogonal to dialyzer and other static typing systems - this is focused on validating map keysets at runtime. Arguably it is not as beneficial when you have records - those could also be viewed as a typed key set and it can be validated statically.

Here’s an interested use of clojure.spec: self-healing code. Would love to see this implemented in Elixir as it complements OTP.



yep I think that Clojure community has very clever people :slight_smile:

1 Like

I have a library that takes some inspiration from clojure.spec in the works, I am excited and looking forward to getting it ready for the first release :).


So finally had some time to work on it, and just released the first usable version of Spec. See this thread Spec: like clojure.spec but for Elixir