Skip to content

Documented declConflict errors #281

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

Merged
merged 2 commits into from
Sep 5, 2020
Merged

Conversation

Woody88
Copy link
Contributor

@Woody88 Woody88 commented Oct 31, 2019

I am not sure if there are other cases when this error occurs, but I think that this should be fine? I am pretty sure that there is a better way to explain this, but this is what I came up with quickly.

@hdgarrood
Copy link
Collaborator

I think this is a little overly specific, as there are indeed a few other cases where this can show up. For example, repeated data constructors, or data constructors whose names conflict with type class names. See tests/purs/failing/DeclConflict*.purs in the compiler repo for more examples.

I don't think your suggested fix really works, though, because writing, say, data X = Y is very different from writing data X = X Y. The former is a type with precisely one inhabitant which you've called Y, the latter is a type which has the same number of inhabitants as some other existing type Y. I think the suggested fix should be to either come up with new names which don't conflict, or to put the conflicting names in a separate module.

@hdgarrood
Copy link
Collaborator

Just to be clear, this file doesn't have to exhaustively list the possibilities for an error like this to occur; I think that would probably end up being counterproductive. I think we should just provide a couple of very basic examples, around the minimum size required to produce this error.

@thomashoneyman
Copy link
Member

@Woody88 what do you think of an update to your PR to something like this?


DeclConflict Error

Example

Each of these pairs will fail with a DeclConflict error.

module Main where

data T = Fail | Fail

data T1 = Fail1
data T2 = Fail1

class Fail2
data T3 = Fail2

Cause

This error occurs when a data constructor, type, or type class conflicts with another data constructor, type, or type class.

Fix

This can be fixed by using non-conflicting names or by putting conflicting names into a separate module. Then, if the names are later used together in a module they can be distinguished via a qualified import:

module Main where

import Module1 as Module1 -- includes: data Works = Works
import Module2 as Module2 -- includes: data Works = Works

x :: Module1.Works
x = Module1.Works

y :: Module2.Works
y = Module2.Works

Copy link
Member

@thomashoneyman thomashoneyman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @hdgarrood that this needs some changes before it's updated.

@Woody88
Copy link
Contributor Author

Woody88 commented Aug 31, 2020

Hi @thomashoneyman @hdgarrood!

No problem, I will add the proposed changes tomorrow.

@hdgarrood
Copy link
Collaborator

Thanks!

@hdgarrood hdgarrood merged commit ec3ae8e into purescript:master Sep 5, 2020
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

Successfully merging this pull request may close these issues.

3 participants