Replacing Marker Interfaces


  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:


Summary: There is a pattern of (definterface IFoo) and subsequent uses of IFoo as a type marker for efficient (instance? IFoo x) checks. This pattern is not platform agnostic and could potentially block improving support for core.logic on CLJS (which does not support definterface according to

I was investigating the possibility of using reader conditionals to port parts of core.logic to CLJS (specifically: core.logic.fd) and noticed the usage of interfaces as type markers.

The problem with this is that there is no definterface in CLJS (to my knowledge; attempting to run (definterface IFoo) fails in a CLJS repl but works in a CLJ repl).

I have started trying to look for a platform-agnostic replacement for the marker interface pattern but wanted to know if there were specific reasons that this pattern was used before diving into actual coding. I also wanted to know if there were already plans to replace this pattern.

Ideally a cross-platform method for achieving this could be implemented. If not, then an alternative method could be defined for and used by CLJS at the cost of some performance.

A possible change would be to replace the marker interfaces with marker protocols, and the instances of instance? with instances of satisfies?.

The following seem to be equivalent in Clojure:

; interfaces
(definterface IFoo)
(definterface IBar)

(deftype T [] IFoo)
(instance? IFoo (T.)) ; true
(instance? IBar (T.)) ; false

; protocols
(defprotocol IFoo)
(defprotocol IBar)

(deftype T [] IFoo)
(satisfies? IFoo (T.)) ; true
(satisfies? IBar (T.)) ; false

However, the protocol version also works in ClojureScript.


There are no comments yet on this issue.


Vote (0)
Watch (1)


  • Created: