Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make package export fantasy-fill #66

Closed
wants to merge 1 commit into from

Conversation

phadej
Copy link
Contributor

@phadej phadej commented Apr 15, 2014

Related to #24 #56

With the fantasy fill you can fill the gaps in your pure functional, monadic fantasies.

var Id = require('./id.js');
var fantasyFill = require('./index.js');

function MyId(x) {
    this.value = x;
}

MyId.of = function (value) {
    return new MyId(value);
};

MyId.prototype.chain = function (action) {
    return action(this.value);
};

console.log('Id: ', fantasyFill(Id).join(", "));
console.log('MyId: ', fantasyFill(MyId).join(", "));

console.log('MyId 3 `map` \\x -> x * x: ', MyId.of(3).map(function (x) { return x * x; }));
Id:  Applicative, Apply, Chain, Functor, Monad, Monoid, Semigroup
MyId:  Applicative, Apply, Chain, Functor, Monad
MyId 3 `map` \x -> x * x:  { value: 9 }

@SimonRichardson
Copy link
Member

This seems like it should go here if anything fantasy-sorcery

@phadej
Copy link
Contributor Author

phadej commented Apr 15, 2014

IMHO it would be nice to have some reasons to add fantasy-land as a dependency to the implementing libraries. So this package could be the spec, but also a common combinator library (like Control.Monad and Control.Applicative packages in Haskell's base).

Then, as a positive side-effect`, you'll see implementations as dependents on npmjs.org and they could use gemnasium to track spec updates. Of course fantasy-land could be added as dependency already now, but, as said, one more reason. This is related to the semver discussion.

@SimonRichardson
Copy link
Member

@phadej now i've added the laws, would it be better that the laws are tested rather than just checking for a function?

var hasChain = typeof constructor.prototype.chain === 'function' && laws.chain.associativity(constructor)(equality)(1);

Then we know for certain that if it quacks like a duck and sounds like a duck then it is a duck.

@SimonRichardson
Copy link
Member

It doesn't seem like this is getting any traction, if you want to keep it open, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants