github purescript/purescript v0.6.7

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

Enhancements

Scoped Type Variables

(#347, @paf31)

This feature allows type variables which are bound by a forall keyword to be used inside type annotations in the body of the function. For example, suppose we want to define a map function on a List type:

data List a = Nil | Cons a (List a)

map :: forall a b. (a -> b) -> List a -> List b
map f = go
  where
  go Nil = Nil
  go (Cons x xs) = Cons (f x) (map f xs) 

To give a type to go, we could previously use type wildcards:

go :: List _ -> List _

Now, we can refer to the types a and b inside the type of go, giving a more precise type:

go :: List a -> List b

Rows In Instance Contexts

(@paf31, @apsk)

This feature allows rows to appear on the left of a => in a type signature. For example, given a MonadEff class:

class MonadEff eff m where
  liftEff :: forall a. Eff eff a -> m a

we can now write the following function which works in any Monad supporting Trace actions:

logging :: forall m a eff. (Monad m, MonadEff (trace :: Trace | eff) m) => String -> m a -> m a
logging s action = do
  liftEff $ trace $ "Starting: " <> s
  a <- action
  liftEff $ trace $ "Done: " <> s
  return a

Improved let bindings in psci

(#782, @paf31)

Any declaration can now be used inside a let binding in psci. For example, we can define data types or foreign imports:

> let data Foo = Foo | Bar | Baz

> let foreign import foo :: Foo -> String

The general form of a let statement in psci now contains one or more declarations of any type, and these declarations simply get added to the current module.

As a bonus, polymorphic functions bound using let now work at multiple type instantiations in psci:

> let f x = x

> if f true then f "true" else f "False"
"true"

Markdown Support in psc-docs

(#802, @paf31)

Markdown can now be used for documentation purposes by using pipe characters to align content. For example:

-- | Create a copy of the array without its first element.
-- |
-- | Running time: `O(n)`, where `n` is the length of the array.
-- |
-- | This function is partial. Specifically, `tail []` is undefined.
tail :: forall a. [a] -> [a]

psc-docs will insert this markdown content verbatim into your generated documentation.

Bug Fixes

  • Modules are rebuilt before a command is executed in psci, to avoid situations where compiled code becomes out-of-date (@paf31)
  • @ is a valid operator name again (#815, @paf31)
  • Reserved module names are now properly escaped (@garyb)

Don't miss a new purescript release

NewReleases is sending notifications on new releases.