@@ -100,6 +100,40 @@ Otherwise it would raise a ``mypy`` error:
100
100
This happens because ``mypy `` is unable to implicitly
101
101
cast ``NoReturn `` to any other type.
102
102
103
+ What is the difference between ``Success `` and ``_Success ``?
104
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105
+
106
+ You might wonder why ``Success `` is a function
107
+ and ``_Success `` is internal type, that should not be used directly.
108
+
109
+ Well, that's a complicated question. Let's find out.
110
+
111
+ Let's begin with ``haskell `` definition:
112
+
113
+ .. code :: haskell
114
+
115
+ Prelude> :t Left 1
116
+ Left 1 :: Num a => Either a b
117
+ Prelude> :t Right 1
118
+ Right 1 :: Num b => Either a b
119
+
120
+ As you can see: ``Left `` (``Failure ``) and ``Right `` (``Success ``)
121
+ are type constructors: that return ``Either a b `` (``Result[b, a] ``) value.
122
+
123
+ It means, that there's no single type ``Left a `` that makes
124
+ sense without ``Right b ``. Only their duality makes sence to us.
125
+
126
+ In ``python `` we have functions that can be used as type constructors.
127
+ That's why we use ``Success `` and ``Failure `` functions.
128
+ But, when we need to implement
129
+ the behaviour of these types - we use real classes inside.
130
+ That's how we know what to do in each particular case.
131
+ In ``haskell `` we use pattern matching for this.
132
+
133
+ That's why we have public
134
+ type constructor functions: ``Success `` and ``Failure ``
135
+ and internal implementation.
136
+
103
137
104
138
API Reference
105
139
-------------
0 commit comments