SCL Types
Basic types
SCL is statically typed language which means that types of the possible values of all variables are known already at compile time. The following types have builtin support:
- Boolean
- Byte, Short, Integer, Long
- Float, Double
- String
- BooleanArray, ByteArray, ShortArray, IntegerArray, LongArray, FloatArray, DoubleArray
- []
- (), (,), (,,), ...
- (->)
- Maybe
- Array
Other types are either imported from the host language or defined in SCL modules.
Some types are parametric (compare to generics in Java or templates in C++). For example, the list type [] has one parameter: the type of the list elements. Thus [Integer] is the type of the integer lists and [String] is the type of string lists. [[Integer]] is the type of the lists of integer lists. Usually parameters are written after the type that is being parametrized: for example Maybe String or Array Integer, but some of the builtin types can be written in a special way in order to make the type expressions more readable:
[a] = [] a (a,b) = (,) a b (a,b,c) = (,,) a b c ... a -> b = (->) a b
Particularly important type is (->), the type of functions. For example, the type of the function computing the length of a string is String -> Integer: the function takes a string as a parameter and returns an integer.
Types of the functions taking multiple parameters are written by composing function types. For example, the type of a function taking nth element of a string list is [String] -> Integer -> String. The function takes a string list and an integer as a parameter and returns a string. Function type operator -> is right associative thus the previous type is equivalent to [String] -> (Integer -> String). Thus the type expression can be read as well as a type of functions taking a string list and returning another function from integers and strings.