Cats-effect: Proposal: rename IO.apply

Created on 24 Apr 2017  路  5Comments  路  Source: typelevel/cats-effect

I see our IO.apply as filling the same niche as foreign import in Haskell; i.e., it's the backdoor to the unsafe part of the language, and the one and only way to construct a new IO primitive. So I think it should be documented more aggressively in these terms and renamed to definePrimitive or something.

I realize nobody will like this idea but I don't care.

Most helpful comment

You're all nuts.

All 5 comments

Indeed, I feel very strongly against this. IO { ... } is enough of a FFI boundary IMO.

I also feel pretty strongly against it. It is the FFI, as you point out, but it's not actually unsafe (though obviously the thunk isn't going to be referentially transparent). Unlike in Haskell, this is the normal case for using IO. Any code which uses IO is going to be using this function all over the place, so any scary naming is just going to be inconvenient and will almost instantly dilute its scare value (when seen everywhere).

We want to encourage people to wrap their effects in IO by making it as pleasant as possible. Getting into IO should be nice; getting out should be extremely unpleasant.

In my experience people don't understand this. It's not loud enough. They don't understand when to use pure and when to use apply. It needs to be painfully obvious that apply doesn't obey the normal rules of substitution. You can't replace IO(expr) with { val a = expr; IO(a) }.

You're all nuts.

LOL Clearly suggesting "more Cake" right before you went to sleep had an unexpected impact on your morning thought processes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ronanM picture ronanM  路  5Comments

RaasAhsan picture RaasAhsan  路  4Comments

kubukoz picture kubukoz  路  6Comments

kailuowang picture kailuowang  路  5Comments

kubukoz picture kubukoz  路  6Comments