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 variablex
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 asputStrLn "Haskell!"
. (This will be run and the result displayed.) - A Haskell
IO
binding, such ascwd <- getCurrentDirectory
. (This will be executed and the result will be bound to the variablecwd
.) - Haskell
type
,data
,class
, andinstance
declarations, such asdata 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.
0 Comments