functional-php / fantasy-land

Specification for interoperability of common algebraic structures in PHP
BSD 3-Clause "New" or "Revised" License
34 stars 10 forks source link

self type considered harmful #10

Closed widmogrod closed 6 years ago

widmogrod commented 6 years ago

When using interface with self as return i.e. Functor new class require reimplementing.

class A implements Functor {
    public function map(callable $function): self {
    }
}

this code results in error

 Declaration of A::map(callable $function): A must be compatible with FunctionalPHP\FantasyLand\Functor::map(callable $function): FunctionalPHP\FantasyLand\Functor in (..)

To fix it, interface should have explicit return type

class A implements Functor {
    public function map(callable $function): Functor {
    }
}
krtek4 commented 6 years ago

What about Apply and Chain ?

widmogrod commented 6 years ago

@krtek4 good catch.

krtek4 commented 6 years ago

:+1: