Hacker News new | past | comments | ask | show | jobs | submit login

I don't really like the description of the IO type so well. Rather, I can say that the type "IO x" is the type of I/O operations that produce a result of type x. The functor/monad functions that can be used include:

- "return x" produces a I/O operation that does nothing and produces the result x.

- "x <$> y" or "fmap x y" produces a I/O operation that does the same thing as y, but the result value is the function x applied to the result of y.

- "x >>= y" produce a I/O operation that when performed, performs x, and then passes the result to the function y, which returns the I/O operation to be performed next.

- "join x" takes the I/O operation x which has the result which is itself a I/O operation; the new one first does x and then the I/O operation which is the result of x.

A I/O operation might have different results when performed multiple times, even if it is the same I/O operation.

Also, I can say that generators in JavaScript seem to form two different monads actually (as far as I can tell), as described by the following table:

  yield x       yield*x
  return x      return yield*x
Also, functors and monads are more than the interface, but also the mathematical properties they have (such as "fmap id = id" etc).



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: