kongware / scriptum

Functional Programming Unorthodoxly Adjusted to Client-/Server-side Javascript
MIT License
383 stars 21 forks source link

Invalid `Yoneda.ap` implementation #360

Closed ivenmarquardt closed 2 years ago

ivenmarquardt commented 2 years ago

While

const add = fun(x => y => x + y, "Number => Number => Number");
const foo = Yoneda.lift(A.Functor) ([1,2]);
const bar = Yoneda.lift(A.Functor) ([3,4]);

Yoneda.ap(A.Apply) 
  (Yoneda.map(add) (foo))
    (bar);

yields the correct type Yoneda<[], Number>

Yoneda.lower(
  Yoneda.ap(A.Apply) 
    (Yoneda.map(add) (foo))
      (bar));

throws the type error

Uncaught TypeError: type mismatch
cannot unify the following types:
Number
(a1 => b1) => a1 => b1
in lambda #2
in argument #1
original fun: Number => Number
original arg: (a => b) => a => b

which doesn't make much sense and thus indicates either an implementation error at the term level or an invalid annotation of one of the nested lambdas.