
Hello! I thought about routes and overlapping. I'm not talking about actual implementation but rather trying to construct simple model. First of all what is overlapping in routes? Simplest definition is routes do not overlap if any URL match to one route or do not match. Bad thing it couldn't be checked statically. Using for example Eric's routes.
/add /#Int
This routes do not overlap. We can make this conclusion because we know SinglePiece instance of Int. Overlapping checker could not have this information. Better definition is. Routes do not overlap is any URL could be mapped to one or zero routes assuming that SinglePiece match any piece. Now lets consider case of unlimited overlapping. Routes are matched from top to bottom. First route to match is selected. If singlePiece or multiPiece field fails then next route is matched. So it's very similar to pattern matching in haskell functions. It has a problem though. There may be inconsitencies. For example:
/ HomeR /#String StrR /#Int IntR
Then roundtrip (route → URL → route) for IntR becomes:
IntR 42 → "/42" → StrR "42"
IMHO overlapping should be disabled by default. Should it be possible to enable overlapping? How should it be resolved. Method above seems to be most intuitive (at least for me). P.S. I didn't touch subsites and multipiece parts for simplicity.

Hi Alexey,
Simple answer is that overlapping is disabled by default. If you want
to allow overlapping, you have to use a separate parseRoutesNoChecking
function, which is not exported from Yesod by default (you have to
look in web-routes-quasi).
Michael
On Thu, Jun 23, 2011 at 11:42 PM, Alexey Khudyakov
Hello!
I thought about routes and overlapping. I'm not talking about actual implementation but rather trying to construct simple model.
First of all what is overlapping in routes? Simplest definition is routes do not overlap if any URL match to one route or do not match. Bad thing it couldn't be checked statically. Using for example Eric's routes.
/add /#Int
This routes do not overlap. We can make this conclusion because we know SinglePiece instance of Int. Overlapping checker could not have this information.
Better definition is. Routes do not overlap is any URL could be mapped to one or zero routes assuming that SinglePiece match any piece.
Now lets consider case of unlimited overlapping. Routes are matched from top to bottom. First route to match is selected. If singlePiece or multiPiece field fails then next route is matched. So it's very similar to pattern matching in haskell functions.
It has a problem though. There may be inconsitencies. For example:
/ HomeR /#String StrR /#Int IntR
Then roundtrip (route → URL → route) for IntR becomes:
IntR 42 → "/42" → StrR "42"
IMHO overlapping should be disabled by default. Should it be possible to enable overlapping? How should it be resolved. Method above seems to be most intuitive (at least for me).
P.S. I didn't touch subsites and multipiece parts for simplicity.
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel

On 26.06.2011 09:13, Michael Snoyman wrote:
Hi Alexey,
Simple answer is that overlapping is disabled by default. If you want to allow overlapping, you have to use a separate parseRoutesNoChecking function, which is not exported from Yesod by default (you have to look in web-routes-quasi).
It's disabled by default but could be enabled. So I have to understand how should it work in case of overlapping. It's reckless to try to write fast function without knowing what's correct. Also at the moment I have idea about routes. Dispatch on constructors works in constant time regardless of number of constructors. I mean functions like this:
f (Con1 _) = ... f (Con2 _) = ... ...
Therefore it could make sense to split routing in two parts. First is to convert route into typed representation and second is to dispatch in that representation. Something along thes lines:
class Routable r where fromRoute :: [Text] → Maybe r renderRoute :: r -> [Text]
dispatch :: MyRoute -> Whatever dispatch = ...
Than it becomes easy to check correctness of routing, benchmark it. And web-routes-quasi will become useful on its own. Subsites do complicate matter but I don't think they could invalidate this scheme. P.S. I only benchmarked data types like that. But execution type do not change from 10 to 300 constructors.
data I = I1 Int | I2 Int ...
participants (2)
-
Alexey Khudyakov
-
Michael Snoyman