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.