diff options
author | Profpatsch <mail@profpatsch.de> | 2024-05-13T14·02+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-05-13T16·09+0000 |
commit | 5ea5dff59780c019d67f0863c6d856d42dbf31b0 (patch) | |
tree | 16518497094e630bbbe41323a3835064d46cc3b4 /users/Profpatsch/my-prelude/src/Arg.hs | |
parent | 53163de836deb795f725995a4e52b81739a1c5eb (diff) |
feat(users/Profpatsch/MyPrelude): add Arg r/8137
Change-Id: I218562c924489ff9cba783dc88ecb8e777c8aac3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11656 Reviewed-by: Profpatsch <mail@profpatsch.de> Autosubmit: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI
Diffstat (limited to 'users/Profpatsch/my-prelude/src/Arg.hs')
-rw-r--r-- | users/Profpatsch/my-prelude/src/Arg.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/users/Profpatsch/my-prelude/src/Arg.hs b/users/Profpatsch/my-prelude/src/Arg.hs new file mode 100644 index 000000000000..a6ffa90924b2 --- /dev/null +++ b/users/Profpatsch/my-prelude/src/Arg.hs @@ -0,0 +1,34 @@ +module Arg where + +import Data.String (IsString) +import GHC.Exts (IsList) +import GHC.TypeLits (Symbol) + +-- | Wrap a function argument into this helper to give it a better description for the caller without disturbing the callsite too much. +-- +-- This has instances for IsString and Num, meaning if the caller is usually a string or number literal, it should Just Work. +-- +-- e.g. +-- +-- @ +-- myFoo :: Arg "used as the name in error message" Text -> IO () +-- myFoo (Arg name) = … +-- @ +-- +-- Will display the description in the inferred type of the callsite. +-- +-- Due to IsString you can call @myFoo@ like +-- +-- @myFoo "name in error"@ +-- +-- This is mostly intended for literals, if you want to wrap arbitrary data, use @Label@. +newtype Arg (description :: Symbol) a = Arg {unArg :: a} + deriving newtype + ( Show, + Eq, + IsString, + IsList, + Num, + Monoid, + Semigroup + ) |