-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom naming hooks for autogenerated code #204
Comments
I'm happy enough with an |
Indeed, how should we design An alternative design would be to thread data Options = ...
defaultOptions :: Options
class DsMonad m => SingMonad m where
getOptions :: m Options
instance SingMonad Q where
getOptions = pure DefaultOptions
newtype SingM m a = SingM (ReaderT Options m a)
withOptions :: Options -> SingM m a -> m a
withOptions opts (SingM x) = runReaderT x opts
instance SingMonad (SingM m) where
getOptions = SingM ask (If you have a better name ideas for With this design, if one wishes to run the TH machinery with a custom set of options, all they have to do is this: $(withOptions myCustomOptions $ genSingletons [''Foo, ''Bar]) Moreover, the |
That design is plausible. We could also imagine allowing users to write a Nothing wrong with your design -- just adding another option. |
I'm not sure that I understand your design fully. Can you provide more details on how this would look from a users' standpoint? |
Reification could find the in-scope set of options. |
If I understand you correctly, the code in |
See ghc-proposals/ghc-proposals#283 But in reality, I tend to agree with you. I just thought it was a cute idea. |
This patch introduces an `Options` data type and an `mtl`-like `OptionsMonad` class for monads that carry `Options`. At present, the only things one can do with `Options` are: * Toggle the generation of `SingKind` instances. Suppressing `SingKind` instances provides an effective workaround for #150. * Hook into the TH machinery's naming conventions for promoted and singled names. This fixes #204. The vast majority of this patch simply adds plumbing by using `OptionsMonad` in places that need it. See the `D.S.TH.Options` module for where most of the new code is housed, as well as the `T150` and `T204` test cases for examples of how to use it.
See #427. |
This patch introduces an `Options` data type and an `mtl`-like `OptionsMonad` class for monads that carry `Options`. At present, the only things one can do with `Options` are: * Toggle the generation of `SingKind` instances. Suppressing `SingKind` instances provides an effective workaround for #150. * Hook into the TH machinery's naming conventions for promoted and singled names. This fixes #204. The vast majority of this patch simply adds plumbing by using `OptionsMonad` in places that need it. See the `D.S.TH.Options` module for where most of the new code is housed, as well as the `T150` and `T204` test cases for examples of how to use it.
This patch introduces an `Options` data type and an `mtl`-like `OptionsMonad` class for monads that carry `Options`. At present, the only things one can do with `Options` are: * Toggle the generation of `SingKind` instances. Suppressing `SingKind` instances provides an effective workaround for #150. * Hook into the TH machinery's naming conventions for promoted and singled names. This fixes #204. The vast majority of this patch simply adds plumbing by using `OptionsMonad` in places that need it. See the `D.S.TH.Options` module for where most of the new code is housed, as well as the `T150` and `T204` test cases for examples of how to use it.
This patch introduces an `Options` data type and an `mtl`-like `OptionsMonad` class for monads that carry `Options`. At present, the only things one can do with `Options` are: * Toggle the generation of `SingKind` instances. Suppressing `SingKind` instances provides an effective workaround for #150. * Hook into the TH machinery's naming conventions for promoted and singled names. This fixes #204. The vast majority of this patch simply adds plumbing by using `OptionsMonad` in places that need it. See the `D.S.TH.Options` module for where most of the new code is housed, as well as the `T150` and `T204` test cases for examples of how to use it.
This patch introduces an `Options` data type and an `mtl`-like `OptionsMonad` class for monads that carry `Options`. At present, the only things one can do with `Options` are: * Toggle the generation of `SingKind` instances. Suppressing `SingKind` instances provides an effective workaround for #150. * Hook into the TH machinery's naming conventions for promoted and singled names. This fixes #204. The vast majority of this patch simply adds plumbing by using `OptionsMonad` in places that need it. See the `D.S.TH.Options` module for where most of the new code is housed, as well as the `T150` and `T204` test cases for examples of how to use it.
* Bump major version to 2.7 * Introduce Options and OptionsMonad This patch introduces an `Options` data type and an `mtl`-like `OptionsMonad` class for monads that carry `Options`. At present, the only things one can do with `Options` are: * Toggle the generation of `SingKind` instances. Suppressing `SingKind` instances provides an effective workaround for #150. * Hook into the TH machinery's naming conventions for promoted and singled names. This fixes #204. The vast majority of this patch simply adds plumbing by using `OptionsMonad` in places that need it. See the `D.S.TH.Options` module for where most of the new code is housed, as well as the `T150` and `T204` test cases for examples of how to use it.
I ran into yet another naming conflict when using
singletons
recently:Compiling this with
singletons-2.3
yields the following (abridged)-ddump-splices
output and error message:Urk. We have a conflict between the
Ratio2
constructor and the singleton constructor forRatio1
. We could conceivably change the rules for generating singleton constructor names so as to avoid this problem, but I struggle to think of something that wouldn't create the potential for ambiguity somewhere else.Instead of finagling the name generation rules, a better solution would be to allow users finer control over what gets generated. In the spirit of
Data.Aeson.TH
, we could offer anOptions
datatype (name subject to bikeshedding) that bundles hooks for generatingName
s. Something like:And then we could provide variants of
singletons
,promote
, etc. that takeOptions
as arguments.The text was updated successfully, but these errors were encountered: