Enhancements
Scoped Type Variables
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
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
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
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.