git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update syntax.rst
331a5dcPhil Freeman
docs/source/syntax.rst+6−10
@@ -152,11 +152,7 @@ Here is an example, using the maybe monad::
152
152
153 data Maybe a = Nothing | Just a
153 data Maybe a = Nothing | Just a
154
154
155− instance Monad Maybe where
155+ isEven :: Number -> Maybe {}
156− ret = Just
157− (>>=) Nothing _ = Nothing
158− (>>=) (Just a) f = f a
159−
160 isEven n | n % 2 == 0 = Just {}
156 isEven n | n % 2 == 0 = Just {}
161 isEven _ = Nothing
157 isEven _ = Nothing
162
158
@@ -165,17 +161,17 @@ Here is an example, using the maybe monad::
165 m <- b
161 m <- b
166 let sum = n + m
162 let sum = n + m
167 isEven sum
163 isEven sum
168− ret sum
164+ return sum
169
165
170``isEven`` adds two values of type ``Maybe Number`` and returns their sum, if the sum is even. If the sum is odd, ``evenSum`` returns ``Nothing``.
166``isEven`` adds two values of type ``Maybe Number`` and returns their sum, if the sum is even. If the sum is odd, ``evenSum`` returns ``Nothing``.
171
167
172−When using ``do`` notation, the corresponding type constructor must be an instance of the ``Prelude.Monad`` type class, which defines the ``ret`` and ``>>=`` functions.
168+When using ``do`` notation, the corresponding type constructor must be an instance of the ``Prelude.Monad`` type class.
173
169
174Statements can have the following form:
170Statements can have the following form:
175
171
176−- ``a <- x`` which desugars to ``m.bind x (\a -> ...)` `
172+- ``a <- x`` which desugars to ``x >>= \a -> ...` `
177−- ``let a = x`` which desugars to ``(\a -> ...)(x)``
178−- ``x`` which desugars to ``m.bind x (\_ -> ...)`` or just ``x`` if this is the last statement.
173+- ``x`` which desugars to ``x >>= \_ -> ...`` or just ``x`` if this is the last statement.
174+- A let binding ``let a = x`` where ``a`` can be either a name or a binder. Note the lack of the ``in`` keyword.
179
175
180Binders can be used on the left hand side of ``<-`` or ``=``. For example::
176Binders can be used on the left hand side of ``<-`` or ``=``. For example::
181
177