I am not sure I would consider it an 'optimization' -- with out this change the desired behavior can not be expressed as far as I can tell.
data GalleryCommon
= ViewImage ImageId [Transform]
deriving (Eq, Ord, Show, Read, Data, Typeable)
The ImageId and Transform properties are used in other url components (not shown here). They have PathInfo instances already.
The Template Haskell or Regular libraries would generate a parser that looks a bit like:
fromPathSegments = (string "ViewImage" *> ViewImage) <$> fromPathSegments <*> fromPathSegments
Without the changes to the type, the TH code would not be able to reuse the existing PathInfo ImageId instance, but would instead be forced to handle the ImageId argument explicitly.. That is really unfortunate, because the path generated by the PathInfo ImageId instance is much cleaner than what TH would generate.
It seems to me that the primary purpose of the PathInfo class is to allow you to build composable parsers / generates for urls. It seems odd to limit the composableness to only the last argument of a constructor..
- jeremy