haskell - Yesod route containing a `Maybe a` argument -
i've been trying utilize maybe a in route. far tried
/u/#maybe userid /u/#(maybe userid) /u/#maybe-userid and
class="lang-hs prettyprint-override">/u/#maybeuserid where
class="lang-hs prettyprint-override">type maybeuserid = maybe userid but without much success.
strangely enough, #maybe-userid compiles fine handler using maybe userid but, it's not able find match new pathpiece instance below.
instance (pathpiece a) => pathpiece (maybe a) frompathpiece s = case s of "nothing" -> nil _ -> $ frompathpiece s topathpiece m = case m of s -> topathpiece s _ -> "nothing" what missing create maybe routes , not having declare type , instance each , every maybe a want use?
edit: instance works fine when using other Ǹothing reason.
edit2: "nothing" -> nothing actualy indicates pathpiece failed parsing, not desired outcome. "nothing" -> nothing right thing.
a route empty parameter (ending slash) reverts route ending previous path piece, "/u/" never match "/u/#maybeuserid"
so there 2 different routes in optional userid proposition:
/u usernoidr /u/#userid userwithidr update:
you may serve them both mutual handler, if want:
getusernoidr = getusermaybe nil getuserwithidr userid = getusermaybe (just userid) haskell routes yesod maybe
No comments:
Post a Comment