Skip to content

Your first program

Type blue on its own to start the REPL, where you can try Blue a line at a time:

$ blue
Blue 0.7.0
Type an expression or a declaration, or :help for commands.
blue> fn double x = x * 2
double : Int -> Int
blue> double 21
it : Int = 42

Blue worked out that double takes an Int and gives an Int; you rarely write types yourself. :type shows the type of anything, :help lists the REPL’s commands, and Ctrl-D (or :quit) leaves.

Save this as hello.blue:

fn greet name = "Hello, " ++ name
fn main () =
print (greet "Blue")
print "2 + 2 is {2 + 2}"
Hello, Blue
2 + 2 is 4

and run it:

Terminal window
blue run hello.blue

blue run checks the whole program, then calls main. ++ joins strings, and anything in braces inside a string, like {2 + 2}, is worked out and put in its place.

To check a program without running it, and see the type of everything in it:

Terminal window
blue check hello.blue
greet : String -> String
main : Unit -> <Console> Unit

main’s type says it takes nothing ((), the Unit value), returns nothing, and uses the Console: printing is an effect, and Blue’s types say which effects a function has. A function whose type has no effects, like greet, does nothing but compute its answer.

Next: an actor that remembers.