[erlang-questions] Emulating phantom types maybe

Tuncer Ayaz <>
Fri Aug 26 00:32:02 CEST 2016


On 26/08/2016, Leandro Ostera <> wrote:
> Couldn't this be achieved by specifically defining a list of characters
> that are lowercased?
>
> -type lowercase_char() :: "a" | "b" | ...
> -type lowercase_string() :: [ lowercase_char() ]

If we limit it to the string example, yes, but as I wrote, this
isn't about strings exclusively.

So, let's ignore lower/upper and think of something like raw vs
sanitized string, if we stay with strings, although there can be
cases where you could specify that constraint as well. Therefore,
let's not focus on strings. Sorry for the bad example.

What I'm looking for is a universal way to subtype
structurally-equivalent values to enforce that function needs_a/1
may only be fed input of type a/0 which may have been generated
by make_a() or make_other_a().


More information about the erlang-questions mailing list