I recently added user defined warnings to the PureScript compiler. This feature will be available in the release following 0.10.5. You can find the feature request here.


To print a warning during compilation, we added a type class called Warn. It is located in the Prim module and is defined as:

class Warn (message :: Symbol)

It is indexed by a Symbol - you can read about symbols here.


If this type class is used as a constraint in a type, for example:

-- inspired by the example on the feature request
trace :: Warn "Do not use 'trace' in production code"
      => forall a. String -> a -> a

When this function is used and the compiler starts solving for the constraints, it will trivially solve the Warn instance and print out the message.


Another use case is a deprecation message with upgrade instructions:

fromList :: Warn "Deprecated `fromList`, use `fromFoldable` instead."
         => forall a. List a -> Foo a

fromFoldable :: forall f a. Foldable f => f a -> Foo a

I’ve written about this on the documentation repo.