我一直在尝试Maybe a
在路线中使用 a 。到目前为止我试过
/u/#Maybe UserId
/u/#(Maybe UserId)
/u/#Maybe-UserId
和
/u/#MaybeUserId
在哪里
type MaybeUserId = Maybe UserId
但没有太大的成功。
奇怪的是,#Maybe-UserId
使用处理程序可以很好地编译,但是,即使使用下面的新实例Maybe UserId
,它也无法找到匹配项。PathPiece
instance (PathPiece a) => PathPiece (Maybe a) where
fromPathPiece s = case s of
"Nothing" -> Nothing
_ -> Just $ fromPathPiece s
toPathPiece m = case m of
Just s -> toPathPiece s
_ -> "Nothing"
我缺少什么来创建路由并且不必为我想要使用Maybe
的每一个声明一个类型和实例?Maybe a
编辑:Ǹothing
除了出于某种原因之外,该实例在使用任何其他东西时都可以正常工作。
edit2: "Nothing" -> Nothing
实际上表示PathPiece
解析失败,这不是预期的结果。"Nothing" -> Just Nothing
做正确的事。