Closed Fresheyeball closed 9 years ago
That would violate referential transparency - every call to channel
creates a distinct channel, whereas a -> Channel a
implies that every time you call channel
with the same value of type a
, you'll get the same channel back (or at the very least a channel which behaves exactly like it). The point of channels is that you can push arbitrary values to them, thus you cannot guarantee value equality for two distinct channels once created. That's why the Eff
is there.
The reason constant
doesn't have an Eff
is the same: for any value n
of a
, you're guaranteed to get a signal which always contains n
. It won't be the same signal, given the current implementation, but two signals created using the same value of a
will always be value equal. Likewise with foldp
et al: calling foldp
twice with the same arguments will yield two signals which will always contain the same values.
The fact that channel
uses constant
as a general signal constructor is an implementation detail. It's untyped in JS, so no assumptions should be made about the type signatures of functions using it inside FFI.
Thank you, that makes sense.
So
channel :: forall a e. a -> Eff (chan :: Chan | e) (Channel a)
is the current type signature forchannel
. But the implementation ofchannel
is just usingconstant
which has a type signature ofconstant :: forall a. a -> Signal a
so its not clear whychannel
has anEff
. Why not? (thanks @michaelficarra for helping me understand this)