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

Type aliases? #16

Open
vendethiel opened this issue Sep 4, 2023 · 2 comments
Open

Type aliases? #16

vendethiel opened this issue Sep 4, 2023 · 2 comments

Comments

@vendethiel
Copy link

vendethiel commented Sep 4, 2023

Hi! I recently found Zydeco and I've been toying with it recently.

I'm wondering if there's a way to declare a type alias, that has the same type as its underlying representation.
Basically, something like type Level = NumRange[1, 80];.
While investigating the libs behind Zydeco, I found out that use Type::Utils -all would give me a declare function (though it seems to be a keyword at other points, because I see declare MyType unquoted?), but I couldn't manage to get it to work doing it either from my main package or from my MAINPKG::Types (that I created originally to work around #15), they both error either when declaring it or when using it (sometimes in an unrelated file that also uses Zydeco...).

Thanks!

@tobyink
Copy link
Owner

tobyink commented Apr 4, 2024

Not pretty, but this works:

use v5.30;

BEGIN {
	package MyTest::Types;
	use Type::Library -base, -utils;
	use Types::Common qw( NumRange );
	declare Level => as NumRange[ 0, 80 ];
}

package MyTest {
	use Zydeco;
	
	class Bucket {
		has fill ( type => MyTest::Types::Level() );
	}
}

say MyTest->new_bucket( fill => 100 );

I agree that a nicer way to declare aliases would be good.

@vendethiel
Copy link
Author

vendethiel commented Apr 5, 2024

Ah, thanks. I was wondering if Exporter::Almighty had such a hatch, but this'll do for now. I also omit the () because otherwise,the type won't parse in method parameter type specifiers.

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

2 participants