You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: errors/PartiallyAppliedSynonym.md
+9-6
Original file line number
Diff line number
Diff line change
@@ -39,20 +39,23 @@ error = IdentityF (Const 5)
39
39
40
40
## Cause
41
41
42
-
A type alias has been partially applied. To properly use a type alias having type parameters, like `type B a` or `type TypeIdentity a`, you must apply it to a type parameter at every location in the program, like `B Int` or `TypeIdentity Int`.
42
+
A type synonym has been partially applied. To properly use a type synonym having type parameters, like `type B a` or `type TypeIdentity a`, you must apply it to a type parameter at every location in the program, like `B Int` or `TypeIdentity Int`.
43
43
44
-
A type synonym *can* be partially applied in the context of a type synonym, however. For example:
44
+
To understand the problem, it may be helpful to review the relevant difference between a "type synonym" and a "data type". A type synonym is effectively a macro, a substitution which is performed after parsing into an AST and before type-checking and compilation, while a data type is a proper entity through the compilation process. Because of this, a type synonym has much more restricted use, while a data type enjoys additional flexibility, such as the ability to be partially applied.
45
+
46
+
Interestingly, a type synonym *can* be partially applied in the context of a type synonym, however. For example:
45
47
46
48
```purescript
47
49
type UserT' f = { firstName :: f String }
48
-
newtype UserNT' = UserNT' (UserT' TypeIdentity)
50
+
u' :: UserT' TypeIdentity
51
+
u' = { firstName: "test" }
49
52
```
50
53
51
54
## Fix
52
55
53
-
Reconsider whether you want to be using a type alias for that particular type declaration. A type synonym is effectively a macro, a substitution which is performed after parsing into an AST and before type-checking and compilation, while a data type exists throughout the compilation process. Because of this, a type synonym has much more restricted use, while a data type enjoys the ability to be partially applied, like a function.
56
+
Reconsider whether you want to use a type synonym for that particular type declaration, or whether to a data type is more appropriate.
54
57
55
-
In the example above, if you want to use the type alias`TypeIdentity`, you will need to apply it to another type alias to produce a concrete type. That concrete type can then be used in a newtype or a function type signature.
58
+
In the example above, if you want to use the type synonym`TypeIdentity`, you will need to apply it to another type synonym to produce a concrete type. That concrete type can then be used in a newtype or a function type signature.
56
59
57
60
```purescript
58
61
type UserT' f = { firstName :: f String }
@@ -64,6 +67,6 @@ um :: UserNT'Maybe
64
67
um = UserNT'Maybe { firstName: Just "test" }
65
68
```
66
69
67
-
And to fix the second example, we can't simply fully apply `X`, as that would produce a kind error, `Could not match kind Type -> Type with kind Type`. The `f` in `IdentityF f a` needs to be kind `Type -> Type`, but here it is kind `Type`. The most appropriate solution is to simply use `A` or `B` as the type alias, as demonstrated in `alsoOk` and `alsoAlsoOk`.
70
+
And to fix the second example, we can't simply fully apply `X`, as that would produce a kind error, `Could not match kind Type -> Type with kind Type`. The `f` in `IdentityF f a` needs to be kind `Type -> Type`, but here it is kind `Type`. The most appropriate solution is to simply use `A` or `B` as the type synonym, as demonstrated in `alsoOk` and `alsoAlsoOk`.
0 commit comments