git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update syntax.rst
commit331a5dca99063a28322509e6875a9237bf6e56fc authorPhil Freeman <paf31@cantab.net> dateWed 23 Apr 2014, 22:27 (13 years ago) parent9f12202
1 file changed+6−10
docs/source/syntax.rst+6−10
docs/source/syntax.rst+6−10
@@ -152,11 +152,7 @@ Here is an example, using the maybe monad::
152152
153153 data Maybe a = Nothing | Just a
154154
155− instance Monad Maybe where
156− ret = Just
157− (>>=) Nothing _ = Nothing
158− (>>=) (Just a) f = f a
159−
155+ isEven :: Number -> Maybe {}
160156 isEven n | n % 2 == 0 = Just {}
161157 isEven _ = Nothing
162158
@@ -165,17 +161,17 @@ Here is an example, using the maybe monad::
165161 m <- b
166162 let sum = n + m
167163 isEven sum
168− ret sum
164+ return sum
169165
170166``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``.
171167
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.
173169
174170Statements can have the following form:
175171
176−- ``a <- x`` which desugars to ``m.bind 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.
172+- ``a <- x`` which desugars to ``x >>= \a -> ...` `
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.
179175
180176Binders can be used on the left hand side of ``<-`` or ``=``. For example::
181177