Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Fantasy-IO does not comply to Fantasyland specs #2

Open
nadameu opened this issue May 11, 2017 · 8 comments
Open

Fantasy-IO does not comply to Fantasyland specs #2

nadameu opened this issue May 11, 2017 · 8 comments

Comments

@nadameu
Copy link

nadameu commented May 11, 2017

According to the Fantasyland spec, v.ap(u.ap(a.map(f => g => x => f(g(x))))) must be equivalent to v.ap(u).ap(a) https://github.com/fantasyland/fantasy-land#apply .

I am using fantasy-io.js and trying to run the following tests:

const log = msg => x => {
  console.log(msg, x);
  return x;
};

const v = IO.of('v');
const u = IO.of(x => `u(${x})`);
const a = IO.of(x => `a(${x})`);

const testA = v.ap(u.ap(a.map(f => g => x => f(g(x)))))
  .map(log('testA = '))
  .unsafePerform();

const testB = v.ap(u).ap(a)
  .map(log('testB = '))
  .unsafePerform();

The result is:
TypeError: f is not a function on the line that says const testA = v.ap(u.ap(a.map(f => g => x => f(g(x)))))

When I swap a and this in the body of the function IO.prototype.ap, the tests succeed:

testA =  a(u(v))
testB =  a(u(v))
@safareli
Copy link
Member

This lib is outdated, it is supporting old version of fantasy-land

@mwalkerwells
Copy link

@nadameu What are you using for the IO monad now? End up writing something?

@safareli
Copy link
Member

It would be better to update this lib then write new one
PRs are welcome!

@mwalkerwells
Copy link

@safareli What are you using to model IO?

@nadameu
Copy link
Author

nadameu commented Aug 17, 2017

@mwalkerwells I usually write my FL implementations from scratch, since I write mostly Greasemonkey scripts, which makes working with libraries (imports/exports) difficult.

Also, most implementations have a lot of methods I usually don't need, and I need my code to be lightweight.

I like this style:

const IO = performUnsafeIO => ({
	performUnsafeIO,
	ap: a => IO(() => a.performUnsafeIO()(performUnsafeIO())),
	chain: f => IO(() => f(performUnsafeIO()).performUnsafeIO()),
	map: f => IO(() => f(performUnsafeIO()))
});
IO.of = x => IO(() => x);

@mwalkerwells
Copy link

Ah, gotcha. I was also actually thinking of forking to be FL compliant. Any reason you haven't submitted a PR upstream?

nadameu added a commit to nadameu/fantasy-io that referenced this issue Aug 17, 2017
@nadameu
Copy link
Author

nadameu commented Aug 18, 2017

Pull request #3 submitted

@mwalkerwells
Copy link

Love it man 👍🏻👍🏻

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

No branches or pull requests

3 participants