clojure-protocol

Clojure - dispatch on return type? (As expressive as Haskell Typeclasses)

∥☆過路亽.° 提交于 2019-12-22 04:26:19
问题 This is a question about the expressiveness of Clojure vs other languages such as Haskell. The broader issue is solutions to the Expression Problem This question reached the conclusion that in general Clojure protocols (and multimethods) were less expressive than Haskell typeclasses because protocols dispatched on first argument, and Haskell typeclasses could dispatch on return type. (Now I think this reasoning is really interesting, and have no interest in starting a language war. I'm just

Does the Clojure compiler check if records and types implement protocols?

爱⌒轻易说出口 提交于 2019-12-13 19:36:41
问题 Is the Clojure compiler meant to check if a record or type that says it instantiates a protocol actually implements the methods listed in it? I'm trying this out now and so far, it doesn't seem to. 回答1: A record can implement a protocol without implementing any of its methods: (defprotocol Structure (weight [this]) (balanced? [this])) (defrecord Mobile [] Structure ) ... is accepted. If you try to use a non-existent method: (balanced? (Mobile.)) ;java.lang.AbstractMethodError: user.Mobile

Is there a Clojure compile-time tool to check if a record or type actually implements a protocol it claims to?

北慕城南 提交于 2019-12-08 18:37:55
问题 Seems the Clojure compiler doesn't do this by default : Does the Clojure compiler check if records and types implement protocols? Any, say, Lein plugins that do this? 回答1: The amazing core.typed introduces "an optional type system for Clojure", as you can see on their official website. Specifically you may want to use their own defprotocol macro (from core.typed wiki) : Protocol definitions should use clojure.core.typed/defprotocol whose syntax is reminiscent of defprotocol and typed fn:

Clojure - dispatch on return type? (As expressive as Haskell Typeclasses)

元气小坏坏 提交于 2019-12-05 02:42:56
This is a question about the expressiveness of Clojure vs other languages such as Haskell. The broader issue is solutions to the Expression Problem This question reached the conclusion that in general Clojure protocols (and multimethods) were less expressive than Haskell typeclasses because protocols dispatched on first argument, and Haskell typeclasses could dispatch on return type. (Now I think this reasoning is really interesting, and have no interest in starting a language war. I'm just interested in clarity of thought). As part of breaking this reasoning down - my question is - can't we