I have an application using Navigation and UrlParser which will have perhaps 200 Routes. Rather than place all the routes in a single file, it would be useful to be able to keep them in other modules, close to where the page rendering takes place.
So, I need to used nested ADTs in my routing.
In the simplest case, this presents no problem.
type OtherAnswer = DontKnow | Perhaps | NoComment
type Route = Yes | No | Other OtherAnswer
route : Url.Parser (Route -> a) a
route =
Url.oneOf
[ Url.map Yes (s "Yes")
, Url.map No (s "")
, Url.map (Other DontKnow) (s "DontKnow")
, Url.map (Other Perhaps) (s "Perhaps")
, Url.map (Other NoComment) (s "NoComment")
]
No problem. But one of the nested ADTs now has to carry a payload, thus:
type OtherAnswer = DontKnow | Perhaps | NoComment String
So, how should the ārouteā function look?
route : Url.Parser (Route -> a) a
route =
Url.oneOf
[ Url.map Yes (s "Yes")
, Url.map No (s "")
, Url.map (Other DontKnow) (s "DontKnow")
, Url.map (Other Perhaps) (s "Perhaps")
, Url.map (Other NoComment) (s "NoComment" </> string)
]
Nope, the last line doesnāt work, because one of the items in Other is āNoComment Stringā, and I am not offering that. Iāve tried everything I can think of, but Iām always an argument short or an argument over.
Iām missing something simple, no doubt, but I would appreciate any help.