New features:
-
Implement visible type applications
The compiler now supports visible type applications, allowing the user to instantiate one or more "visible" type variables to a specific type.
A "visible" type variable is a type variable in a
forall
binder that appears prefixed with an@
, like the following example:id :: forall @a. a -> a -- or with kinds: `forall (@a :: Type). a -> a` id a = a
We can then use type application syntax to instantiate this binding to a specific type:
idInt :: Int -> Int idInt = id @Int example :: Int example = id @Int 0
Type variables appearing in
class
ordata
are automatically visible, meaning that they do not require annotations:data Maybe a = Just a | Nothing nothingInt :: Maybe Int nothingInt = Nothing @Int class Identity a where identity :: a -> a instance Identity Int where identity a = a identityInt = identity @Int -- This throws a `NoInstanceFound` error. identityNumber = identity @Number
Lastly, visible type variables can also be skipped with a wildcard (i.e.
_
)data Either a b = Left a | Right b example = Left @_ @Number 0
Note that performing a type application with a type that has no visible type variables throws an error:
module Main where id :: forall a. a -> a id a = a idInt = id @Int {- Error found: in module Main at Main.purs:6:9 - 6:16 (line 6, column 9 - line 6, column 16) An expression of polymorphic type with the invisible type variable a: forall a. a -> a cannot be applied to: Int while inferring the type of id in value declaration idInt See https://github.com/purescript/documentation/blob/master/errors/CannotApplyExpressionOfTypeOnType.md for more information, or to contribute content related to this error. -}
Similarly, monomorphic types also cannot be used for type applications:
module Main where idInt :: Int -> Int idInt a = a example = idInt @Int {- Error found: in module Main at Main.purs:6:11 - 6:21 (line 6, column 11 - line 6, column 21) An expression of monomorphic type: Int -> Int cannot be applied to: Int while inferring the type of idInt in value declaration example See https://github.com/purescript/documentation/blob/master/errors/CannotApplyExpressionOfTypeOnType.md for more information, or to contribute content related to this error. -}
-
Exclude files from compiler input (#4480 by @i-am-the-slime)
The compiler now supports excluding files from the globs given to it as input.
This means there's now a new option forpurs compile
, namely
--exclude-files
(or the short version-x
):> purs compile --help Usage: purs compile [FILE] [-x|--exclude-files ARG] [-o|--output ARG] ... Compile PureScript source files Available options: -h,--help Show this help text FILE The input .purs file(s). -x,--exclude-files ARG Glob of .purs files to exclude from the supplied files. ...
This allows you to keep related files closer together (that is, colocate them).
Consider a setup like the following:
src/ Main.purs View/ LoginPage.purs LoginPageTest.purs LoginPageStories.purs
In order to exclude the files in the example above you can now invoke
purs
like this and it will only compileLoginPage.purs
:purs compile "src/**/*.purs" --exclude-files "src/**/*Stories.purs" -x "src/**/*Test.purs"
With
spago
, the equivalent command is:spago build --purs-args '-x "src/**/*Test.purs" -x "src/**/*Stories.purs"'