github purescript/purescript v0.10.1

latest releases: v0.15.16-1, v0.15.16-0, v0.15.15...
7 years ago

Breaking Changes

The new functional dependencies feature fixes type inference in some cases involving multi-parameter type classes. However, due to a bug in the compiler, some of those expressions were previously type checking where they should not have. As a result, it is necessary to add functional dependencies to some classes in order to make previous code type-check in some cases. Known examples are:

  • MonadEff and MonadAff
  • MonadState, MonadReader, and the rest of the MTL-style classes in transformers

New Features

Data.Newtype Deriving

(@garyb)

It is now possible to derive the Newtype class for any data declaration which is a newtype, using the existing deriving instance syntax:

newtype Test = Test String

derive instance newtypeTest :: Newtype Test _

Note that the second type argument should be specified as a wildcard, and will be inferred.

Added type level string functions

(@FrigoEU)

The Prim module now defines the TypeString and TypeConcat type constructors, which can be used to build more descriptive error messages which can depend on types, using the Fail constraint:

instance cannotShowFunctions 
    :: Fail ("Function type " <> TypeString (a -> b) <> " cannot be shown.") 
    => Show (a -> b) where
  show _ = "unreachable"

infixl 6 type TypeConcat as <>

--dump-corefn

(@rightfold)

The compiler now supports the --dump-corefn option, which causes the functional core to be dumped in output/**/corefn.json. This should be useful for implementing new backends which interpret the functional core.

Newtype Deriving

(@paf31)

It is now possible to derive type class instances for newtypes, by reusing the instance for the underlying type:

newtype X = X String

derive newtype instance showX :: Show X

Note that it is possible to derive instances for multi-parameter type classes, but the newtype must only appear as the last type argument.

Allow anonymous accessor chains (_.a.b)

(@rvion)

Anonymous record accessor syntax has been extended to work with chains of one or more accessors:

getBaz = _.foo.bar.baz

Functional Dependencies (@paf31)

The type class solver now supports functional dependencies. A multi-parameter type class can define dependencies between its type arguments by using the -> operator:

class Stream el s | s -> el where
  cons :: el -> (Unit -> s) -> s
  uncons :: s -> { head :: el, tail :: s }

Here, the s and el type arguments are related by a single functional dependency, which ensures that there is at most one instance for any given type s. Alternatively, the type s determines the type el, i.e. there is an implicit function from types s to types el. This information can be used by the solver to infer types where it was previously not possible.

See the following examples for more information:

Enhancements

  • Return qualifier from explicit/hiding imports (@nwolverson)
  • Verify entry points exist in psc-bundle (@kritzcreek)
  • Improved error messages for record subsumption (@FrigoEU)

psc-ide

Bug Fixes

  • Fix usage detection for operators (@garyb)
  • Fix handling of duplicate module imports in JS codegen (@garyb)
  • Fix a small bug in the type pretty-printer (@paf31)
  • Fix function application judgment (@paf31)
  • Fix inlining for $ and # operators (@garyb)
  • Fix everywhereOnTypesTopDown (@ianbollinger)
  • Fix unification of string literals (@paf31)

Infrastructure

  • Support aeson-1.0 (@phadej)
  • Support http-client-0.5 (@phadej)
  • Safer installation from source in INSTALL.md (@hdgarrood)

Implementation

  • Fix most HLint warnings (@ianbollinger)
  • Fixing imports (@charleso)
  • Export desugarDecl from Sugar.ObjectWildcards (@rvion)
  • Remove legacy ObjectGetter and update doc (@rvion)

Don't miss a new purescript release

NewReleases is sending notifications on new releases.