yesodweb / shakespeare

Haml-like template files that are compile-time checked
http://www.yesodweb.com/book/shakespearean-templates
MIT License
136 stars 76 forks source link

`mkMessage` should support context parsing #282

Closed jezen closed 1 month ago

jezen commented 3 months ago

Currently, you can use mkMessage like this.

mkMessage "App" "messages" "en"

It will ultimately produce Haskell code like this.

data AppMessage
  = MsgFoo {}
  | MsgBar {}
  -- etc…

instance RenderMessage App AppMessage where
  renderMessage _ ((:) msg _) MsgFoo {} | msg == pack "en" = pack ("Foo" :: String)
  renderMessage _ ((:) msg _) MsgBar {} | msg == pack "en" = pack ("Bar" :: String)
  -- etc…

Similar to how mkYesodSubData can parse out typeclass contexts and type variables, I think mkMessage should support something like this.

mkMessage "(MyClass master) => SubApp master" "messages" "en"

It should produce Haskell code like this.

data SubAppMessage
  = MsgFoo {}
  | MsgBar {}
  -- etc…

instance (MyClass master) => RenderMessage (SubApp master) SubAppMessage where
  renderMessage _ ((:) msg _) MsgFoo {} | msg == pack "en" = pack ("Foo" :: String)
  renderMessage _ ((:) msg _) MsgBar {} | msg == pack "en" = pack ("Bar" :: String)
  -- etc…

Currently, this fails to compile with the following error.

    Illegal type constructor or class name: ‘(MyClass master) => SubApp masterMessage’
    When splicing a TH declaration:
      data (MyClass master) => SubApp masterMessage
    = MsgFoo {}
    | MsgBar {}