Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

untagged union types or refinement type support #3

Open
lafirest opened this issue Oct 11, 2021 · 0 comments
Open

untagged union types or refinement type support #3

lafirest opened this issue Oct 11, 2021 · 0 comments

Comments

@lafirest
Copy link

Abstract

In Erang, we can often see the following code,
-type text() :: string() | binary().
-type print_text(text()) -> ok.

In Hamler, we can use type class to simulation

class IsText a

instance IsText (List Char)
instance IsText Binary

printText :: forall a. IsText a => a -> IO ()
printText a = do
xxxx

But if we can directly support untagged union, may be better

Design

Untagged Union

data Text = String | Binary

Refinement Type

data Text = forall a.IsText a
IsText a = let type = typeof(a) in
a == typeof(String) || a == typeof(Binary)

or
printText :: (forall a. IsText a) -> IO ()

This is like the following Erlang code:
-spec print_text(A) -> xxx
when A :: string() | binary().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant