Copyright | (c) Sirui Lu 2021-2024 |
---|---|
License | BSD-3-Clause (see the LICENSE file) |
Maintainer | siruilu@cs.washington.edu |
Stability | Experimental |
Portability | GHC only |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Grisette.Internal.TH.Ctor.SmartConstructor
Description
Synopsis
- makeSmartCtorWith :: (String -> String) -> Name -> Q [Dec]
- makePrefixedSmartCtor :: String -> Name -> Q [Dec]
- makeNamedSmartCtor :: [String] -> Name -> Q [Dec]
- makeSmartCtor :: Name -> Q [Dec]
Documentation
makeSmartCtorWith :: (String -> String) -> Name -> Q [Dec] Source #
Generate constructor wrappers that wraps the result in a container with
TryMerge
with provided name transformer.
makeSmartCtorWith (\name -> "mrg" ++ name) ''Maybe
generates
mrgNothing :: (Mergeable (Maybe a), Applicative m, TryMerge m) => m (Maybe a) mrgNothing = mrgSingle Nothing
makePrefixedSmartCtor Source #
Arguments
:: String | Prefix for generated wrappers |
-> Name | The type to generate the wrappers for |
-> Q [Dec] |
Generate constructor wrappers that wraps the result in a container with
TryMerge
.
makePrefixedSmartCtor "mrg" ''Maybe
generates
mrgNothing :: (Mergeable (Maybe a), Applicative m, TryMerge m) => m (Maybe a) mrgNothing = mrgSingle Nothing mrgJust :: (Mergeable (Maybe a), Applicative m, TryMerge m) => a -> m (Maybe a) mrgJust = \x -> mrgSingle (Just x)
Arguments
:: [String] | Names for generated wrappers |
-> Name | The type to generate the wrappers for |
-> Q [Dec] |
Generate constructor wrappers that wraps the result in a container with
TryMerge
with provided names.
makeNamedSmartCtor ["mrgTuple2"] ''(,)
generates
mrgTuple2 :: (Mergeable (a, b), Applicative m, TryMerge m) => a -> b -> u (a, b) mrgTuple2 = \v1 v2 -> mrgSingle (v1, v2)
Generate constructor wrappers that wraps the result in a container with
TryMerge
.
makeSmartCtor ''Maybe
generates
nothing :: (Mergeable (Maybe a), Applicative m, TryMerge m) => m (Maybe a) nothing = mrgSingle Nothing just :: (Mergeable (Maybe a), Applicative m, TryMerge m) => a -> m (Maybe a) just = \x -> mrgSingle (Just x)