algo.generic

dispatch for fmap multimethod shouldn't be on type of second argument

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

AFAICT having fmap dispatch on the type of the second argument makes it practically impossible to define fmap for arbitrary functions, since the type is different for each function:

user> (type type)
clojure.core$type
user> (type fn?)
clojure.core$fn_QMARK_
user> (type not=)
clojure.core$not_EQ_
user>

However, there's a perfectly reasonable definition of fmap for functions (fmap = comp).

To my mind the simplest/best thing to do is just have a Functor protocol and have fmap call a function in it, with the order of arguments reversed so that dispatch will happen correctly.

Activity

Hide
Konrad Hinsen added a comment -

I added an fmap implementation for the IFn interface, which covers all functions:
https://github.com/clojure/algo.generic/commit/4dd3e17e494b7b6f43cda045d3162b0f60df7599

Changing fmap to a protocol-based implementation would break all existing code that adds fmap implementations.

Show
Konrad Hinsen added a comment - I added an fmap implementation for the IFn interface, which covers all functions: https://github.com/clojure/algo.generic/commit/4dd3e17e494b7b6f43cda045d3162b0f60df7599 Changing fmap to a protocol-based implementation would break all existing code that adds fmap implementations.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: