Skip to content

Add type arguments of site data to subroutes #1865

@L0neGamer

Description

@L0neGamer

In #1366, contexts and type arguments were added and are now possible for sites. However, these type arguments are not included in the subroutes, which means the flexibility that was granted from them is somewhat lost.

Here is a motivating example:

mkYesodSubData "(SiteClass master) => SiteBuilder master" [parseRoutes|
!/#{ItemId master} HomeR:
  /edit EditR:
    /for/#{Key (PersistUser master)} ForR GET
|]

Here we want to mention the master argument in the same way that we can use it in "top level" routes.

The code generated includes (approximately):

instance SiteClass master =>
         RenderRoute (SiteBuilder master) where
  data Route (SiteBuilder master)
    = HomeR (ItemId master) EditR
    deriving ()
  ...
data EditR
  = ForR (Key (PersistUser master))

Which fails to compile because master is not in scope for the top level definition of EditR.

I suggest that the type arguments which are already collected for the top level routes are also passed down to the subroutes, meaning that instead of data EditR = ... we'd have data EditR master = ....

This would be a breaking change unfortunately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions