Ciao Marco,
I was wondering if such a patch would make sense:
diff --git a/src/Instances/Reader/ReaderApplicative.php b/src/Instances/Reader/ReaderApplicative.php
index 6a36d4a..afc02c3 100644
--- a/src/Instances/Reader/ReaderApplicative.php
+++ b/src/Instances/Reader/ReaderApplicative.php
@@ -15,7 +15,9 @@ use Marcosh\LamPHPda\Reader;
use Marcosh\LamPHPda\Typeclass\Applicative;
/**
- * @implements Applicative<ReaderBrand>
+ * @template E
+ *
+ * @implements Applicative<ReaderBrand<E>>
*
* @psalm-immutable
*/
@@ -24,7 +26,6 @@ final class ReaderApplicative implements Applicative
/**
* @template A
* @template B
- * @template E
*
* @param HK1<ReaderBrand<E>, callable(A): B> $f
* @param HK1<ReaderBrand<E>, A> $a
@@ -41,7 +42,6 @@ final class ReaderApplicative implements Applicative
/**
* @template A
* @template B
- * @template E
*
* @param callable(A): B $f
* @param HK1<ReaderBrand<E>, A> $a
@@ -57,7 +57,6 @@ final class ReaderApplicative implements Applicative
/**
* @template A
- * @template E
*
* @param A $a
*
@@ -67,6 +66,11 @@ final class ReaderApplicative implements Applicative
*/
public function pure($a): Reader
{
- return Reader::reader(static fn ($_) => $a);
+ return Reader::reader(
+ /**
+ * @param E $_
+ */
+ static fn ($_) => $a
+ );
}
}
diff --git a/src/Instances/Reader/ReaderApply.php b/src/Instances/Reader/ReaderApply.php
index f09282d..d2f0451 100644
--- a/src/Instances/Reader/ReaderApply.php
+++ b/src/Instances/Reader/ReaderApply.php
@@ -15,7 +15,9 @@ use Marcosh\LamPHPda\Reader;
use Marcosh\LamPHPda\Typeclass\Apply;
/**
- * @implements Apply<ReaderBrand>
+ * @template E
+ *
+ * @implements Apply<ReaderBrand<E>>
*
* @psalm-immutable
*/
@@ -24,10 +26,9 @@ final class ReaderApply implements Apply
/**
* @template A
* @template B
- * @template E
*
- * @param HK1<ReaderBrand, callable(A): B> $f
- * @param HK1<ReaderBrand, A> $a
+ * @param HK1<ReaderBrand<E>, callable(A): B> $f
+ * @param HK1<ReaderBrand<E>, A> $a
*
* @return Reader<E, B>
*
@@ -51,10 +52,9 @@ final class ReaderApply implements Apply
/**
* @template A
* @template B
- * @template E
*
* @param callable(A): B $f
- * @param HK1<ReaderBrand, A> $a
+ * @param HK1<ReaderBrand<E>, A> $a
*
* @return Reader<E, B>
*
diff --git a/src/Instances/Reader/ReaderFunctor.php b/src/Instances/Reader/ReaderFunctor.php
index 447199f..aba1993 100644
--- a/src/Instances/Reader/ReaderFunctor.php
+++ b/src/Instances/Reader/ReaderFunctor.php
@@ -15,7 +15,9 @@ use Marcosh\LamPHPda\Reader;
use Marcosh\LamPHPda\Typeclass\Functor;
/**
- * @implements Functor<ReaderBrand>
+ * @template E
+ *
+ * @implements Functor<ReaderBrand<E>>
*
* @psalm-immutable
*/
@@ -24,10 +26,9 @@ final class ReaderFunctor implements Functor
/**
* @template A
* @template B
- * @template E
*
* @param callable(A): B $f
- * @param HK1<ReaderBrand, A> $a
+ * @param HK1<ReaderBrand<E>, A> $a
*
* @return Reader<E, B>
*
@@ -38,6 +39,9 @@ final class ReaderFunctor implements Functor
$readerA = Reader::fromBrand($a);
return Reader::reader(
+ /**
+ * @param E $env
+ */
static fn ($env) => $f($readerA->runReader($env))
);
}
diff --git a/src/Instances/Reader/ReaderMonad.php b/src/Instances/Reader/ReaderMonad.php
index 0d7e813..da75edf 100644
--- a/src/Instances/Reader/ReaderMonad.php
+++ b/src/Instances/Reader/ReaderMonad.php
@@ -15,7 +15,9 @@ use Marcosh\LamPHPda\Reader;
use Marcosh\LamPHPda\Typeclass\Monad;
/**
- * @implements Monad<ReaderBrand>
+ * @template E
+ *
+ * @implements Monad<ReaderBrand<E>>
*
* @psalm-immutable
*/
@@ -24,10 +26,9 @@ final class ReaderMonad implements Monad
/**
* @template A
* @template B
- * @template E
*
- * @param HK1<ReaderBrand, callable(A): B> $f
- * @param HK1<ReaderBrand, A> $a
+ * @param HK1<ReaderBrand<E>, callable(A): B> $f
+ * @param HK1<ReaderBrand<E>, A> $a
*
* @return Reader<E, B>
*
@@ -41,10 +42,9 @@ final class ReaderMonad implements Monad
/**
* @template A
* @template B
- * @template E
*
- * @param HK1<ReaderBrand, A> $a
- * @param callable(A): HK1<ReaderBrand, B> $f
+ * @param HK1<ReaderBrand<E>, A> $a
+ * @param callable(A): HK1<ReaderBrand<E>, B> $f
*
* @return Reader<E, B>
*
@@ -55,6 +55,9 @@ final class ReaderMonad implements Monad
$readerA = Reader::fromBrand($a);
return Reader::reader(
+ /**
+ * @param E $env
+ */
static fn ($env) => Reader::fromBrand($f($readerA->runReader($env)))->runReader($env)
);
}
@@ -62,10 +65,9 @@ final class ReaderMonad implements Monad
/**
* @template A
* @template B
- * @template E
*
* @param callable(A): B $f
- * @param HK1<ReaderBrand, A> $a
+ * @param HK1<ReaderBrand<E>, A> $a
*
* @return Reader<E, B>
*
@@ -78,7 +80,6 @@ final class ReaderMonad implements Monad
/**
* @template A
- * @template E
*
* @param A $a
*
But then, these new psalm issues are raised:
$ ./vendor/bin/psalm --no-cache
Target PHP version: 7.4 (inferred from composer.json)
Scanning files...
Analyzing files...
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░EEEE░░░░░░░░░░ 60 / 81 (74%)
░░░░░░░░░░░░░░░░░░░░░
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderApplicative.php:33:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderApplicative as mixed>, B:fn-marcosh\lamphpda\typeclass\apply::apply as mixed>' for Marcosh\LamPHPda\Typeclass\Apply::apply is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderApplicative::apply 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderApplicative as mixed, B:fn-marcosh\lamphpda\instances\reader\readerapplicative::apply as mixed>' (see https://psalm.dev/123)
* @return Reader<E, B>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderApplicative.php:49:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderApplicative as mixed>, B:fn-marcosh\lamphpda\typeclass\functor::map as mixed>' for Marcosh\LamPHPda\Typeclass\Functor::map is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderApplicative::map 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderApplicative as mixed, B:fn-marcosh\lamphpda\instances\reader\readerapplicative::map as mixed>' (see https://psalm.dev/123)
* @return Reader<E, B>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderApplicative.php:63:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderApplicative as mixed>, A:fn-marcosh\lamphpda\typeclass\applicative::pure as mixed>' for Marcosh\LamPHPda\Typeclass\Applicative::pure is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderApplicative::pure 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderApplicative as mixed, A:fn-marcosh\lamphpda\instances\reader\readerapplicative::pure as mixed>' (see https://psalm.dev/123)
* @return Reader<E, A>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderApply.php:33:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderApply as mixed>, B:fn-marcosh\lamphpda\typeclass\apply::apply as mixed>' for Marcosh\LamPHPda\Typeclass\Apply::apply is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderApply::apply 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderApply as mixed, B:fn-marcosh\lamphpda\instances\reader\readerapply::apply as mixed>' (see https://psalm.dev/123)
* @return Reader<E, B>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderApply.php:59:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderApply as mixed>, B:fn-marcosh\lamphpda\typeclass\functor::map as mixed>' for Marcosh\LamPHPda\Typeclass\Functor::map is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderApply::map 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderApply as mixed, B:fn-marcosh\lamphpda\instances\reader\readerapply::map as mixed>' (see https://psalm.dev/123)
* @return Reader<E, B>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderFunctor.php:33:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderFunctor as mixed>, B:fn-marcosh\lamphpda\typeclass\functor::map as mixed>' for Marcosh\LamPHPda\Typeclass\Functor::map is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderFunctor::map 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderFunctor as mixed, B:fn-marcosh\lamphpda\instances\reader\readerfunctor::map as mixed>' (see https://psalm.dev/123)
* @return Reader<E, B>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderMonad.php:33:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderMonad as mixed>, B:fn-marcosh\lamphpda\typeclass\apply::apply as mixed>' for Marcosh\LamPHPda\Typeclass\Apply::apply is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderMonad::apply 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderMonad as mixed, B:fn-marcosh\lamphpda\instances\reader\readermonad::apply as mixed>' (see https://psalm.dev/123)
* @return Reader<E, B>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderMonad.php:49:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderMonad as mixed>, B:fn-marcosh\lamphpda\typeclass\monad::bind as mixed>' for Marcosh\LamPHPda\Typeclass\Monad::bind is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderMonad::bind 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderMonad as mixed, B:fn-marcosh\lamphpda\instances\reader\readermonad::bind as mixed>' (see https://psalm.dev/123)
* @return Reader<E, B>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderMonad.php:72:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderMonad as mixed>, B:fn-marcosh\lamphpda\typeclass\functor::map as mixed>' for Marcosh\LamPHPda\Typeclass\Functor::map is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderMonad::map 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderMonad as mixed, B:fn-marcosh\lamphpda\instances\reader\readermonad::map as mixed>' (see https://psalm.dev/123)
* @return Reader<E, B>
ERROR: ImplementedReturnTypeMismatch - src/Instances/Reader/ReaderMonad.php:86:16 - The inherited return type 'Marcosh\LamPHPda\HK\HK1<Marcosh\LamPHPda\Brand\ReaderBrand<E:Marcosh\LamPHPda\Instances\Reader\ReaderMonad as mixed>, A:fn-marcosh\lamphpda\typeclass\applicative::pure as mixed>' for Marcosh\LamPHPda\Typeclass\Applicative::pure is different to the implemented return type for Marcosh\LamPHPda\Instances\Reader\ReaderMonad::pure 'Marcosh\LamPHPda\Reader<E:Marcosh\LamPHPda\Instances\Reader\ReaderMonad as mixed, A:fn-marcosh\lamphpda\instances\reader\readermonad::pure as mixed>' (see https://psalm.dev/123)
* @return Reader<E, A>
------------------------------
10 errors found
------------------------------
Checks took 4.49 seconds and used 58.837MB of memory
Psalm was able to infer types for 100% of the codebase