Skip to content
This repository was archived by the owner on Aug 6, 2018. It is now read-only.
This repository was archived by the owner on Aug 6, 2018. It is now read-only.

Confusion with the signature of the function used in chain #5

@paulvictor

Description

@paulvictor

Am here refering to the chain method in

Writer.prototype.chain = function(f) {
return Writer(() => {
const result = this.run();
const t = f(result._1).run();
return Tuple2(t._1, result._2.concat(t._2));
});
};
.

Writer.prototype.chain = function(f) {
    return Writer(() => {
        const result = this.run(); //1
        const t = f(result._1).run(); //2
        return Tuple2(t._1, result._2.concat(t._2)); //3
    });
};

Am using T, S, R as arbitrary type variables.
Here let the type of result from line 1 is Tuple2(T, Monoid), so result._2 is a Monoid, t is of type Tuple2(S, Monoid), so t._2 is a Monoid, both got by run()ning the monad constructor. In line 3 the 2nd part of the tuple is result._2.concat(t._2), which translates to type Monoid.concat(Monoid). I feel something's not right here, right now am using js Array which kind of is easy in that it doesn't care if I concat an array of an element or the element itself, the result is the same. Is there something amiss here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions