From c4c9581d2aed32a46d16856163539a7733977a89 Mon Sep 17 00:00:00 2001 From: Woodson Delhia Date: Thu, 31 Oct 2019 12:27:42 +0900 Subject: [PATCH 1/2] Documented declConflict errors --- errors/DeclConflict.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/errors/DeclConflict.md b/errors/DeclConflict.md index 360d782c..cc4d49a0 100644 --- a/errors/DeclConflict.md +++ b/errors/DeclConflict.md @@ -3,19 +3,28 @@ ## Example ```purescript -module ShortFailingExample where +data MyType = A | B -... +data MyType2 = C | D + +data MyType3 = MyType3 { x :: Int } + +data MyType4 = MyType | MyType2 | MyType3 ``` ## Cause -Explain why a user might see this error. +This error shows up when an a defined type (i.e: MyType, MyType2, etc...) is being defined as a data constructor for another data type definition (i.e: MyType4). ## Fix +This can be fixed by simply wrapping these pre-defined data types in a new data constrcutor. +```purescript +data MyType = A | B -- Suggest possible solutions. +data MyType2 = C | D -## Notes +data MyType3 = MyType3 { x :: Int } + +data MyType4 = T MyType | T2 MyType2 | T3 MyType3 +``` -- Additional notes. From 1a30c2ada56dc641650ed0586549f9cf47586352 Mon Sep 17 00:00:00 2001 From: Woodson Delhia Date: Wed, 2 Sep 2020 21:33:30 +0900 Subject: [PATCH 2/2] Updated DeclConflict.md --- errors/DeclConflict.md | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/errors/DeclConflict.md b/errors/DeclConflict.md index cc4d49a0..5c6ea0a5 100644 --- a/errors/DeclConflict.md +++ b/errors/DeclConflict.md @@ -1,30 +1,35 @@ # `DeclConflict` Error ## Example - +Each of these pairs will fail with a DeclConflict error. ```purescript -data MyType = A | B +module Main where -data MyType2 = C | D +data T = Fail | Fail -data MyType3 = MyType3 { x :: Int } +data T1 = Fail1 +data T2 = Fail1 -data MyType4 = MyType | MyType2 | MyType3 +class Fail2 +data T3 = Fail2 ``` ## Cause -This error shows up when an a defined type (i.e: MyType, MyType2, etc...) is being defined as a data constructor for another data type definition (i.e: MyType4). +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 simply wrapping these pre-defined data types in a new data constrcutor. +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: ```purescript -data MyType = A | B +module Main where -data MyType2 = C | D +import Module1 as Module1 -- includes: data Works = Works +import Module2 as Module2 -- includes: data Works = Works -data MyType3 = MyType3 { x :: Int } +x :: Module1.Works +x = Module1.Works -data MyType4 = T MyType | T2 MyType2 | T3 MyType3 +y :: Module2.Works +y = Module2.Works ```