Skip to content

Commit

Permalink
Improved TypeSynonymInstance error page
Browse files Browse the repository at this point in the history
Removed italic and bold formatting
Linked to language feature documentation
Improved wording
Removed distracting example code
  • Loading branch information
stefanholzmueller authored Apr 12, 2017
1 parent e59db92 commit 0fc9749
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions errors/TypeSynonymInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ instance showMass :: Show Mass where

## Cause

*Type synonyms* are merely aliases (usually created to avoid verbose type annotations) and do not declare a new unique type. It is still possible to use the synonym and its equivalent type interchangeably:
[Type synonyms](https://github.com/purescript/documentation/blob/master/language/Types.md#type-synonyms) are merely aliases (usually created to avoid verbose type annotations) and do not declare a new unique type. It is still possible to use the synonym and its equivalent type interchangeably.

```purescript
velocity = 123.456 :: Mass -- oops
```

Since every value that structually matches the type synonym could be considered of the same type, it is not allowed to implement type classes based on type synonyms.
Since every value that structually matches the type synonym could be considered of the same type, it is not allowed to implement [type classes](https://github.com/purescript/documentation/blob/master/language/Type-Classes.md) based on type synonyms.

## Fix

If a type is wrapped in a **newtype** instead, it becomes a different type than the underlying type. Newtypes can be used as type class instances:
If a type is wrapped in a [Newtype](https://github.com/purescript/documentation/blob/master/language/Types.md#newtypes) instead, it is considered a different type than the underlying type by the type checker. Newtypes can have type class instances declared for them:

```purescript
newtype Mass = Mass Number
Expand Down

0 comments on commit 0fc9749

Please sign in to comment.