News for hackers. Stuff that matters.
Re:Monads are monoids in the category of endofunctors by dwohnitmok on Thursday September 09, 2021 @09:27PM (#28476762)
In theory you could have something like

  interface Mappable<A> {
    // Interfaces don't quite cut it here, because you want 
    // `map` to return a specific implementation of 
    // Mappable, not a general Mappable, but we'll let that 
    // slide for the purposes of exposition
    map<B>(f: A => B): Mappable<B>
  }

  class MyWeirdMappable<A>(val myCounter: Int, val myValue: A) implements Mappable<A> {

    // Notice the return type is MyWeirdMappable not 
    // Mappable, as mentioned earlier
    map<B>(f: A => B): MyWeirdMappable<B> {
      if (myCounter == 0) {
        return this
      } else {
        return MyWeirdMappable(myCounter + 1, f(myValue))
      }
    }
  }
Although this fulfills the contract of `Mappable`, it's not a `Functor`, because `map(identity)` doesn't always return the same (or equivalent) `MyWeirdMappable`.

There are no comments on this comment yet.