Elm: how does Mailbox work? -
say create mailbox
using mailbox = signal.mailbox action
, type action = blah
, later can send actions mailbox
using signal.send mailbox.address blah
, allows me listen on mailbox.signal
, how so? mean, after all, type mailbox
alias of {address : signal.address action, signal : signal.signal action}
, because that, in elm, there 1 signal type, in above scenario, don't have tell elm bind mailbox.signal
mailbox.address
, elm figure out because of one-to-one correspondence between address , signal of type?
the ability mailbox put events send signal entirely based on "magic", is, it's implemented natively (in javascript) , not implement yourself. that's why it's built-in in standard libraries.
creating mailbox imperative, effectful action (shhh, don't tell anyone). if use:
mailbox1 = signal.mailbox blah mailbox2 = signal.mailbox blah
those 2 mailboxes distinct. send message mailbox2.address
result in message on mailbox2.signal
not mailbox1.signal
. breaks referential transparency, bad, it's not breaking everything. (this may go far tangent, because need signal
output , can't have signal (signal something)
, in practice unmanaged effect of mailbox creation not messing things up). "leak" fixed @ point in future. there proposal big changes staged in different versions of language.
Comments
Post a Comment