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

GADT type params and inlining #9989

Open
nadako opened this issue Dec 12, 2020 · 1 comment
Open

GADT type params and inlining #9989

nadako opened this issue Dec 12, 2020 · 1 comment
Labels
strong-belgian-ale Issue is legit - solution probably requires achieving Ballmer Peak type-system
Milestone

Comments

@nadako
Copy link
Member

nadako commented Dec 12, 2020

I extracted this from tink_sql:

enum ExprData<T> {
	EBinOp<A, B, Ret>(op:BinOp<A, B, Ret>, a:Expr<A>, b:Expr<B>):ExprData<Ret>;
}

enum BinOp<A, B, Ret> {
	Like<T:String>:BinOp<T, T, Bool>;
}

abstract Expr<T>(ExprData<T>) {
	inline function new(e) {
		this = e;
	}

	@:from static function ofData<T>(d:ExprData<T>):Expr<T> {
		return new Expr(d);
	}

	public function like(b:Expr<String>):Expr<Bool> {
		return EBinOp(Like, this, b);
	}
}

My first question is whether the like method should compile? Because within that function this is ExprData<T>, where T is supposed to be an unconstrained type parameter and it doesn't sound like it should pass the T:String constraint check of Like.

Secondly, if we add inline to the ofData method, we actually get an error talking about this:

src/Main.hx:19: characters 23-27 : error: Expr.T should be String
src/Main.hx:19: characters 23-27 : ... have: (ExprData<String>) -> ...
src/Main.hx:19: characters 23-27 : ... want: (ExprData<Expr.T>) -> ...
src/Main.hx:19: characters 23-27 : ... For function argument 'a'

And thirdly, looks like have and want are swapped in this error message?

@RealyUniqueName RealyUniqueName added this to the Design milestone Dec 13, 2020
@Simn Simn added the strong-belgian-ale Issue is legit - solution probably requires achieving Ballmer Peak label Feb 18, 2021
@Simn
Copy link
Member

Simn commented Feb 18, 2021

I have removed some distractions so that we can look at the actual issue:

enum ExprData<T> {
	EBinOp<A>(op : BinOp<A>, a : Expr<A>);
}

enum BinOp<A> {
	Like<T:String>:BinOp<T>;
}

abstract Expr<T>(ExprData<T>) {
	@:from
	static inline function ofData<T>(d:ExprData<T>):Expr<T> {
		return null;
	}

	public function like():Expr<Bool> {
		return EBinOp(Like, this);
	}
}

This seems to be mostly about the @:from cast because it fails properly if we use from ExprData<T> instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strong-belgian-ale Issue is legit - solution probably requires achieving Ballmer Peak type-system
Projects
None yet
Development

No branches or pull requests

3 participants