scotty-web / scotty

Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp (Official Repository)
http://hackage.haskell.org/package/scotty
BSD 3-Clause "New" or "Revised" License
1.72k stars 134 forks source link

simplify RoutePattern type #254

Open chessai opened 4 years ago

chessai commented 4 years ago

see #156 :

This is a proof-of-concept intended to provoke some discussion about why the RoutePattern data type is as it is, and whether it can be modified to give users more power to write modular routing code. I would like to write combinators for RoutePatterns, but it isn't possible to do anything very useful without duplicating the code that is in the internal function matchRoute. Examples of useful RoutePattern combinators would be matching either of two patterns, or both. However, I noticed that matchRoute turns any RoutePattern into a function that would fit in the Function constructor. So, why do we need the other constructors? This patch shows that if we move the logic from matchRoute out into the capture and literal functions, then the need for the various RoutePattern ADT constructors vanishes, and thus users' own combinators for routes no longer need to handle the different cases of RoutePattern.


commit of interest : https://github.com/scotty-web/scotty/pull/156/commits/01906eb5ca65247d4599e5e50a7b787fada4412e