Skip to content

Commit 29de859

Browse files
committed
add a warning about the Reference constructor being non-referentially transparent
1 parent 4d57039 commit 29de859

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

effect/ref.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from ._dispatcher import TypeDispatcher
55
from ._sync import sync_performer
66

7+
__all__ = [
8+
'Reference', 'ReadReference', 'ModifyReference', 'perform_read_reference',
9+
'perform_modify_reference', 'reference_dispatcher']
10+
711

812
class Reference(object):
913
"""
@@ -12,6 +16,15 @@ class Reference(object):
1216
functional way.
1317
1418
Compare to Haskell's ``IORef`` or Clojure's ``atom``.
19+
20+
:note: Warning: Instantiating a Reference causes an implicit side-effect.
21+
In other words, ``Reference`` is not a referentially transparent
22+
function, and you can't use equational reasoning on it: the a call to
23+
Reference is not interchangeable with the *result of* a call to
24+
Reference, since identity matters. If you want to create references in
25+
purely functional code, you can use the :obj:`effect.Func` intent:
26+
`effect.Effect(effect.Func(Reference))`.
27+
1528
"""
1629

1730
# TODO: Add modify_atomic that either uses a lock or a low-level

0 commit comments

Comments
 (0)