Skip to content

Commit ed7338b

Browse files
committed
Fixed operator precedence problem in GUIDE examples.
The examples all needed parentheses to work. Fixes #56.
1 parent c11efec commit ed7338b

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

GUIDE.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ Our next routes require extracting an integer `PostId`.
9090
```purescript
9191
post :: Match MyRoute
9292
post =
93-
Post <$> lit "posts" *> int
93+
Post <$> (lit "posts" *> int)
9494
9595
postEdit :: Match MyRoute
9696
postEdit =
97-
PostEdit <$> lit "posts" *> int <* lit "edit"
97+
PostEdit <$> (lit "posts" *> int <* lit "edit")
9898
```
9999

100100
Note the use of the `*>` and `<*` operators. These let us direct the focus of
@@ -107,7 +107,7 @@ And now finally, we need to extract multiple segments for `PostBrowse`.
107107
```purescript
108108
postBrowse :: Match MyRoute
109109
postBrowse =
110-
PostBrowse <$> lit "posts" *> str <*> str
110+
PostBrowse <$> (lit "posts" *> str <*> str)
111111
```
112112

113113
The `<*>` combinator has arrows on both sides because we want both values.
@@ -144,9 +144,9 @@ We can also go ahead and inline our parsers.
144144
myRoute :: Match MyRoute
145145
myRoute = oneOf
146146
[ PostIndex <$ lit "posts"
147-
, Post <$> lit "posts" *> int
148-
, PostEdit <$> lit "posts" *> int <* lit "edit"
149-
, PostBrowse <$> lit "posts" *> str <*> str
147+
, Post <$> (lit "posts" *> int)
148+
, PostEdit <$> (lit "posts" *> int <* lit "edit")
149+
, PostBrowse <$> (lit "posts" *> str <*> str)
150150
]
151151
```
152152

@@ -161,8 +161,8 @@ myRoute =
161161
lit "posts" *> oneOf
162162
[ pure PostIndex
163163
, Post <$> int
164-
, PostEdit <$> int <* lit "edit"
165-
, PostBrowse <$> str <*> str
164+
, PostEdit <$> (int <* lit "edit")
165+
, PostBrowse <$> (str <*> str)
166166
]
167167
```
168168

@@ -179,9 +179,9 @@ myRoute :: Match MyRoute
179179
myRoute =
180180
lit "posts" *> oneOf
181181
[ PostIndex <$ end
182-
, Post <$> int <* end
183-
, PostEdit <$> int <* lit "edit" <* end
184-
, PostBrowse <$> str <*> str <* end
182+
, Post <$> (int <* end)
183+
, PostEdit <$> (int <* lit "edit" <* end)
184+
, PostBrowse <$> (str <*> str <* end)
185185
]
186186
```
187187

@@ -193,9 +193,9 @@ the routes followed by an `end`, so we would still have to rearrange them.
193193
myRoute :: Match MyRoute
194194
myRoute =
195195
lit "posts" *> oneOf
196-
[ PostEdit <$> int <* lit "edit"
196+
[ PostEdit <$> (int <* lit "edit")
197197
, Post <$> int
198-
, PostBrowse <$> str <*> str
198+
, PostBrowse <$> (str <*> str)
199199
, pure PostIndex
200200
] <* end
201201
```
@@ -211,9 +211,9 @@ with the `root` combinator.
211211
myRoute :: Match MyRoute
212212
myRoute =
213213
root *> lit "posts" *> oneOf
214-
[ PostEdit <$> int <* lit "edit"
214+
[ PostEdit <$> (int <* lit "edit")
215215
, Post <$> int
216-
, PostBrowse <$> str <*> str
216+
, PostBrowse <$> (str <*> str)
217217
, pure PostIndex
218218
] <* end
219219
```

0 commit comments

Comments
 (0)