Difference between revisions of "SCL Types"

From Developer Documents
Jump to navigation Jump to search
Line 23: Line 23:
 
a -> b = (->) a b
 
a -> b = (->) a b
 
</pre>
 
</pre>
When multiple arrows are written in sequence, they are associated right, i.e
+
 
<pre>
+
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.
a -> b -> c = a -> (b -> c)
+
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 integer as a parameter and returns String. Function type operator -> is associated right, i.e the previous type is equivalent to [String] -> (Integer -> String).
</pre>
 

Revision as of 07:00, 5 September 2012

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 [] is 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 integer as a parameter and returns String. Function type operator -> is associated right, i.e the previous type is equivalent to [String] -> (Integer -> String).