This is mostly possible already, like so:

@type params(k, v) :: %{k => v}
@spec handle_params(params(s, s)) :: ok when s :: String.t

While Erlang doesn't support expressing guards on the generic parameters in a 
type definition, Elixir could just convert such definitions to the Erlang 
compatible form by replacing the type variables with the concrete type. In 
general though I tend to deal with the verbosity problem by extracting the 
noisy type name into its own definition that is more easily used, e.g.:

@type param_key :: String.t
@type param_val :: String.t
@type params :: %{param_key => param_val}

This has the advantage of being easier to read and easier to change in the 
future (the `params` type doesn't need to change if the range of types for 
keys/values changes).

Paul

On Sun, Jul 7, 2019, at 9:11 PM, Rich Morin wrote:
> While editing a file of @type statements, it occurred to me that it would be
> convenient to be able to abridge them like @spec statements. For example:
> 
>  @type params :: %{ String.t => String.t }
> 
> could be rewritten as:
> 
>  @type params :: %{ s => s } when s: String.t
> 
> Of course, this should also be possible with @typep statements.
> 
> Nu?
> 
> -r
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elixir-lang-core/704BDCAC-CEF8-4A4D-8D6B-29C54BA25F54%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/adf0755d-dfb0-4ce7-92dc-5fa3b459a1ee%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to