What code can I put in the playground?

A Haskell playground consists of a sequence of playground statements. Playground statements can be any of the following: 

  • A simple Haskell expressions, such as map (+1) [1..10].
  • A let binding, such as let x = sqrt 2. (The variable x will be bound to the expression.) Let bindings can bind variables, but they can also include function definitions (including optional function signatures).
  • A Haskell expression of type IO t, such as putStrLn "Haskell!". (This will be run and the result displayed.)
  • A Haskell IO binding, such as cwd <- getCurrentDirectory. (This will be executed and the result will be bound to the variable cwd.)
  • Haskell type, data, class, and instance declarations, such as data Rose a = Rose a [a]. (The declared type and data constructors are available in all subsequent playground statements.)
  • Import declarations, such as import Graphics.SpriteKit. (The imported values and types are available in all subsequent playground statements.)
  • GHC pragmas, such as {-# LANGUAGE TypeFamilies #-}. (The pragmas apply to all subsequent playground statements.)

Playground code uses indentation just like other Haskell code. In particular, each line in the playground editor that starts in the leftmost column marks the beginning of a new playground statement. So, here we have got two playground statements:

let x = 1
    y = 2
x + y

The first playground statement is the let binding (binding both x and y). The second statement is the addition. As in this example, statements can make use of variables, functions, and types defined in preceding statements.

Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk