Use `urlTo` in a `Mail`

I’d like to call some functions that live inside Application.Helper.Controller and use ?context :: ControllerContext. Here’s a simplified version:

module Web.Mail.Users.Confirmation where
import Web.View.Prelude
import IHP.MailPrelude

data ConfirmationMail = ConfirmationMail { user :: User }

instance BuildMail ConfirmationMail where
    subject = "Subject"
    to ConfirmationMail { .. } = Address { addressName = Just "F L", addressEmail = "" }
    from = ""
    html ConfirmationMail { .. } = [hsx|
        Hello World
        <a href={redirectExample}>View link</a>
             redirectExample :: (?context :: ControllerContext) => Text
             redirectExample = urlTo PostsAction

This results with an error:

The context in a mail can be different when the mail is sent from an IHP Script. In those cases the context is ?context :: FrameworkConfig. So the ?context variable can have a different type depenending on where the email is sent from. For that reason you need to be less specific, e.g. by using _ here:

             redirectExample :: _ => Text
             redirectExample = urlTo PostsAction

That worked. I’ll create a PR to add that to the docs.

Is there a way, instead of using the hole (_), to be explicit about the allowed types?

Thanks, yes it should be this:

             redirectExample :: forall context. (?context :: context, ConfigProvider context) => Text
             redirectExample = urlTo PostsAction

Thanks. Show example how to send a link from Mail by amitaibu · Pull Request #1894 · digitallyinduced/ihp · GitHub