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

Document GHC-10498 #519

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Lib where

areDifferent :: Eq a => a -> a -> Maybe (a, a)
areDifferent x y
| x == y = Nothing
areDifferent x y = Just (x, y)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Lib where

areDifferent :: a -> a -> Maybe (a, a)
areDifferent x x = Nothing
areDifferent x y = Just (x, y)
25 changes: 25 additions & 0 deletions message-index/messages/GHC-10498/function-arguments/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Duplicate function arguments
---

```
Lib.hs:4:14: error: [GHC-10498]
• Conflicting definitions for ‘x’
Bound at: Lib.hs:4:14
Lib.hs:4:16
• In an equation for ‘areDifferent’
|
4 | areDifferent x x = Nothing
|
```

*Advanced topic:* somewhat surprisingly, you are allowed
to duplicate arguments of type-level functions as in

```haskell
{-# LANGUAGE DataKinds, TypeFamilies #-}
type family IsElem x xs where
IsElem _ '[] = 'False
IsElem x (x ': xs) = 'True
IsElem x (_ ': xs) = IsElem x xs
```
12 changes: 12 additions & 0 deletions message-index/messages/GHC-10498/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Conflicting definitions
summary: The same entity has more than one definition
severity: error
introduced: 9.8.1
---

GHC does not allow the same entity to have more than one
definition. In some contexts it can figure out which one
is supposed to shadow another: local definitions take
priority over global definitions, etc. Shadowing is just a warning, GHC-63397. However, if the definitions are on the same
level it becomes a fatal error.
3 changes: 3 additions & 0 deletions message-index/messages/GHC-10498/type-parameters/after/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Lib where

data Pair a = Pair a a
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Lib where

data Pair a a = Pair a a
13 changes: 13 additions & 0 deletions message-index/messages/GHC-10498/type-parameters/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Duplicate datatype parameters
---

```
Lib.hs:3:11: error: [GHC-10498]
Conflicting definitions for ‘a’
Bound at: Lib.hs:3:11
Lib.hs:3:13
|
3 | data Pair a a = Pair a a
|
```
7 changes: 7 additions & 0 deletions message-index/messages/GHC-10498/typo/after/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Lib where

function :: Int -> Int
function 1 = 1
function 2 = 2
function 3 = 3
function _ = 4
7 changes: 7 additions & 0 deletions message-index/messages/GHC-10498/typo/before/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Lib where

function :: Int -> Int
function 1 = 1
function 2 = 2
functlon 3 = 3
function _ = 4
18 changes: 18 additions & 0 deletions message-index/messages/GHC-10498/typo/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Just a typo
---

```
Lib.hs:7:1: error: [GHC-29916]
Multiple declarations of ‘function’
Declared at: Lib.hs:4:1
Lib.hs:7:1
|
7 | function _ = 4
|
```

Because of a typo (`functlon` instead of `function`)
GHC parses the third equation as a definition of
`functlon` (without a type signature), while the fourth
equation becomes the second, conflicting definition of `function`.
8 changes: 8 additions & 0 deletions message-index/messages/GHC-10498/wildcards/after/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{-# LANGUAGE NamedFieldPuns #-}

module Lib where

data Foo = Foo { x :: Int, y :: Int }

foo :: Foo -> Int -> Int
foo Foo{y} x = x + y
8 changes: 8 additions & 0 deletions message-index/messages/GHC-10498/wildcards/before/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{-# LANGUAGE RecordWildCards #-}

module Lib where

data Foo = Foo { x :: Int, y :: Int }

foo :: Foo -> Int -> Int
foo Foo{..} x = x + y
17 changes: 17 additions & 0 deletions message-index/messages/GHC-10498/wildcards/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Implicit duplication because of `RecordWildCards`
---

```
Lib.hs:8:9: error: [GHC-10498]
• Conflicting definitions for ‘x’
Bound at: Lib.hs:8:9-10
Lib.hs:8:13
• In an equation for ‘foo’
|
8 | foo Foo{..} x = x + y
|
```

Consider using `NamedFieldPuns` to be more explicit
about which variables are bound where.
Loading