Suppose I have the following type alias:
type alias MyType =
{ my_string : String
, my_num : Int
}
As of now my_string
can consist of any string and my_num
can consist of any int.
Could I create a type alias that would allow me to restrict it’s possible values further beyond just it’s base type? Say I wanted my_num
to only be some integer between 0 and 127, if I was defining a type in Elixir I could write something like
@type MyType :: %{
my_string: String.t(),
my_num: 0..127
}
where 0..127
is shorthand for “a range of integers from 0 to 127”.
I could even write
@type MyType :: %{
my_string: String.t(),
my_num: 0..127 | String.t()
}
if I wanted to allow my_num
to also be an arbitrary string (for some reason).
Is there any equivalent in Elm?