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

Error "illegal type constraint parameter" #7614

Open
stephentetley opened this issue Apr 23, 2024 · 3 comments
Open

Error "illegal type constraint parameter" #7614

stephentetley opened this issue Apr 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@stephentetley
Copy link
Contributor

stephentetley commented Apr 23, 2024

I'm working on changing Iterable to have an associated Elm type rather than being Iterable[t: Type -> Type].

At the moment I'm not able to assert that Iterable's Elm associated type is an instance of Order. Have I got the syntax wrong or is this not implemented yet?

enqueueAll from MutQueue shows what I'm trying to do:


///
/// Enqueues each element in `l` into `mq`.
///
pub def enqueueAll(mq: MutQueue[Iterable.Elm[m], r], m: m): Unit \ r with Iterable[m], Order[Iterable.Elm[m]] =
    foreach(x <- m) {
        enqueue(mq, x)
    }

-- Syntax Error -------------------------------------------------- MutQueue.flix

>> Illegal type constraint parameter.

113 |     pub def enqueueAll(mq: MutQueue[Iterable.Elm[m], r], m: m): Unit \ r with Iterable[m], Order[Iterable.Elm[m]] =
                                                                                                 ^^^^^^^^^^^^^^^^^^^^^^
                                                                                                 illegal type constraint parameter
        

Thanks

@magnus-madsen
Copy link
Member

@mlutze Does this work?

@mlutze
Copy link
Member

mlutze commented Apr 23, 2024

It's indeed illegal at the moment; we need to discuss what exactly should be allowed.

Meanwhile, there is a workaround:

def enqueueAll(mq: MutQueue[Iterable.Elm[m], r], m: m): Unit \ r with Iterable[m], Order[freevar] where Iterable.Elm[m] ~ freevar
                                                                                         ^^^^^^^                          ^^^^^^^

We just add another type variable and associate it with both Iterable.Elm[m] and Order.

@stephentetley
Copy link
Contributor Author

Thanks Matthew, I had to bind it within the "function part" of the type signature:

pub def enqueueAll(mq: MutQueue[elt, r], m: m): Unit \ r with Iterable[m], Order[elt] where Iterable.Elm[m] ~ elt =

@magnus-madsen magnus-madsen added the bug Something isn't working label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants