-
Notifications
You must be signed in to change notification settings - Fork 149
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
test: add tests for associated type multiple Eff
s and types
#7555
base: master
Are you sure you want to change the base?
test: add tests for associated type multiple Eff
s and types
#7555
Conversation
@mlutze can you help me pinpoint the instance error? I really don't see how this is a valid instance error. mod Test.Dec.Assoc.Type.Eff.Multiple {
////////////////////////////////////////////////////////
// Type Definitions //
////////////////////////////////////////////////////////
eff Observe {
pub def captureInt32(x: Int32): Unit
pub def captureString(x: String): Unit
}
enum Split[e: Eff, a: Type] {
case Nothing,
case Value(a),
case Pending(a -> Unit \ e, a)
}
trait Composable[a] {
pub type E: Eff
pub type B: Type -> Type
pub type C: Eff -> Type -> Type
pub def compose(f: a -> Unit \ Composable.E[a], x: a): Composable.C[a][Composable.E[a], Composable.B[a][a]]
pub def reduce(x: Composable.C[a][Composable.E[a], Composable.B[a][a]]): Composable.B[a][a] \ Composable.E[a]
}
instance Composable[Vector[a]] with Composable[a] {
pub type E = Composable.E[a]
pub type B = Vector
pub type C = Split
pub def compose(f: Vector[a] -> Unit \ Composable.E[a], x: Vector[a]): Split[Composable.E[a], Vector[a]] =
Split.Pending(f, x)
pub def reduce(x: Split[Composable.E[a], Vector[a]]): Vector[a] \ Composable.E[a] = match x {
case Split.Nothing => Vector#{}
case Split.Value(v) => v
case Split.Pending(f, v) => f(v); v
}
}
}
|
I think it is because of the |
Ah thanks! :) |
Okay so now it says that it is an irreducible associated type. Is it because of the recurrence of |
Irreducible shouldn't happen anymore, so it's probably a bug. Can you post the new program and the error message? |
Ah I was on latest release rather than |
@jaschdoc Is this blocked or OK? |
No I don't believe so. Just haven't finished writing everything. I think I was reconsidering the design. |
Error trait Transformable[a] {
pub type E: Eff
pub type B: Type
pub def transform(x: a): Transformable.B[a] \ Transformable.E[a]
}
pub def transformAndCheckEq[b](eq: Transformable.B[a], x: a): Bool \ Transformable.E[a] with Transformable[a], Eq[b] where Transformable.B[a] ~ b =
Transformable.transform(x) == eq
|
Error trait Composable[a] {
pub type E: Eff
pub type B: Type -> Type
pub type C: Eff -> Type -> Type
pub def compose(f: a -> Unit \ Composable.E[a], x: a): Composable.C[a][Composable.E[a], Composable.B[a][a]]
pub def reduce(x: Composable.C[a][Composable.E[a], Composable.B[a][a]]): Composable.B[a][a] \ Composable.E[a]
}
pub def composeAndReduceEq[a: Type](eq: Composable.B[a][a], f: a -> Unit \ Composable.E[a], x: a): Bool \ Composable.E[a] with Composable[a], Eq[a] where Composable.B[a] ~ a =
Composable.reduce(Composable.compose(f, x)) == eq
|
// Polymorphic functions using Composable // | ||
//////////////////////////////////////////////////////// | ||
|
||
pub def composeAndReduceEq(eq: Composable.B[a][a], f: a -> Unit \ Composable.E[a], x: a): Bool \ Composable.E[a] with Composable[a], Eq[a] where Composable.B[a][a] ~ a = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm stuck on this function. Not sure how to resolve this:
❌ -- Syntax Error -------------------------------------------------- file:///.../TestEffMultiple.flix
>> Illegal equality constraint.
126 | pub def composeAndReduceEq(eq: Composable.B[a][a], f: a -> Unit \ Composable.E[a], x: a): Bool \ Composable.E[a] with Composable[a], Eq[a] where Composable.B[a][a] ~ a =
^^^^^^^^^^^^^^^^^^^^^^
Equality constraints must have the form: `Assoc[var] ~ Type`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The where
clause can never be true. Imagine Composable.B[a]
is defined as List
. Then we are trying to unify List[a] ~ a
which is impossible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is it impossible to do what I'm trying to achieve?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least for that constraint, yes.
Does this not work without the constraint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need equality on the type C
where C
is the associated type of an instance for B
which again is an associated type for an instance for A
if that makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh noooooo that's a bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes me happy haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ -- Syntax Error -------------------------------------------------- file:///.../TestEffMultiple.flix
>> Illegal equality constraint.
126 | pub def composeAndReduceEq(eq: Composable.B[a][a], f: a -> Unit \ Composable.E[a], x: a): Bool \ Composable.E[a] with Composable[a], Eq[b] where Composable.B[a][a] ~ b =
^^^^^^^^^^^^^^^^^^^^^^
Equality constraints must have the form: `Assoc[var] ~ Type`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's a trickier problem. We can't currently do a constraint Eq[X[a]]
if X is abstract. It's a design question. See https://hackage.haskell.org/package/base-4.15.0.0/docs/Data-Functor-Classes.html#t:Eq1
Related to #7424