@@ -94,20 +94,24 @@ post =
9494
9595postEdit :: Match MyRoute
9696postEdit =
97- PostEdit <$> (lit "posts" *> int <* lit "edit")
97+ PostEdit <$> (lit "posts" *> int) <* lit "edit"
9898```
9999
100100Note the use of the ` *> ` and ` <* ` operators. These let us direct the focus of
101101the value we want to consume. In ` postEdit ` , we want to consume the ` int ` ,
102102but we also need to match the "edit" suffix. The arrows point to the value we
103103want.
104104
105+ Note that in general parentheses are required when using ` *> ` since the
106+ operator precedence is not what is required (resulting in type errors
107+ otherwise.)
108+
105109And now finally, we need to extract multiple segments for ` PostBrowse ` .
106110
107111``` purescript
108112postBrowse :: Match MyRoute
109113postBrowse =
110- PostBrowse <$> (lit "posts" *> str <*> str)
114+ PostBrowse <$> (lit "posts" *> str) <*> str
111115```
112116
113117The ` <*> ` combinator has arrows on both sides because we want both values.
@@ -145,8 +149,8 @@ myRoute :: Match MyRoute
145149myRoute = oneOf
146150 [ PostIndex <$ lit "posts"
147151 , Post <$> (lit "posts" *> int)
148- , PostEdit <$> (lit "posts" *> int <* lit "edit")
149- , PostBrowse <$> (lit "posts" *> str <*> str)
152+ , PostEdit <$> (lit "posts" *> int) <* lit "edit"
153+ , PostBrowse <$> (lit "posts" *> str) <*> str
150154 ]
151155```
152156
@@ -161,8 +165,8 @@ myRoute =
161165 lit "posts" *> oneOf
162166 [ pure PostIndex
163167 , Post <$> int
164- , PostEdit <$> ( int <* lit "edit")
165- , PostBrowse <$> ( str <*> str)
168+ , PostEdit <$> int <* lit "edit"
169+ , PostBrowse <$> str <*> str
166170 ]
167171```
168172
@@ -179,9 +183,9 @@ myRoute :: Match MyRoute
179183myRoute =
180184 lit "posts" *> oneOf
181185 [ PostIndex <$ end
182- , Post <$> ( int <* end)
183- , PostEdit <$> ( int <* lit "edit" <* end)
184- , PostBrowse <$> ( str <*> str <* end)
186+ , Post <$> int <* end
187+ , PostEdit <$> int <* lit "edit" <* end
188+ , PostBrowse <$> str <*> str <* end
185189 ]
186190```
187191
@@ -193,9 +197,9 @@ the routes followed by an `end`, so we would still have to rearrange them.
193197myRoute :: Match MyRoute
194198myRoute =
195199 lit "posts" *> oneOf
196- [ PostEdit <$> ( int <* lit "edit")
200+ [ PostEdit <$> int <* lit "edit"
197201 , Post <$> int
198- , PostBrowse <$> ( str <*> str)
202+ , PostBrowse <$> str <*> str
199203 , pure PostIndex
200204 ] <* end
201205```
@@ -211,9 +215,9 @@ with the `root` combinator.
211215myRoute :: Match MyRoute
212216myRoute =
213217 root *> lit "posts" *> oneOf
214- [ PostEdit <$> ( int <* lit "edit")
218+ [ PostEdit <$> int <* lit "edit"
215219 , Post <$> int
216- , PostBrowse <$> ( str <*> str)
220+ , PostBrowse <$> str <*> str
217221 , pure PostIndex
218222 ] <* end
219223```
0 commit comments