Table of Contents
1 Types
- GF is statically typed: You cannot say something like … a = 3 ; a = "Foo" ; …
- GF makes a distinction into abstract syntax/concrete syntax as well as resource modules
1.0.1 Basic types
- GF also support some basic types
- Python has strings (called `str`). GF has strings (called `Str`).
- Python has integers (called `int`). GF has integers (called `Int`).
- Python has floating-point numbers (called `float`). GF's are called `Float`.
- These types can be used in resource modules and concrete syntax files
- Strings vs. String tuples
- Substrings can be concatenated with +
- Sentences in GF are kind of lists of strings, ++ concatenates lists of strings
Example:
resource SimpleTypes = open Predef,Prelude in { oper s : Str = "foo" + "bar" ; st : Str = "foo" ++ "bar"; i : Predef.Int = 42; f : Predef.Float = 23.5; b : Bool = False ; }
1.0.2 Enumeration types
- The only kind of enumeration types in GF are the so-called param types
Example:
resource Param = { param Gender = F | M ; Number = Sg | Pl ; Case = Nom | Gen | Acc | Dat ; }
1.0.3 Compound types
- GF has three kinds of compound types, tables, records and tuples, Python has dictionaries, tuples and lists
- GF does not really have lists
- Keys in tables usually are *param*s and keys in records are literal identifier
Example:
resource Compound = Param ** { -- Content of Param.gf -- param -- Gender = F | M ; -- Number = Sg | Pl ; -- Case = Nom | Gen | Acc | Dat ; param Person = P1 | P2 | P3 ; oper sleep : Number => Person => Str = -- Declaration table { -- Definition Sg => table { P1 => "sleep" ; P2 => "sleep" ; P3 => "sleeps" } ; Pl => table { P1 => "sleep" ; P2 => "sleep" ; P3 => "sleep" } }; theSg : { s : Str ; n : Number } = -- Declaration { s = "the" ; n = Sg } ; -- Definition man : { s : Number => Case => Str ; g : Gender } -- Declaration = { s = table { Sg => table { Nom => "man" ; Gen => "man's" ; Dat => "man" ; Acc => "man" } ; Pl => table { Gen => "men's" ; _ => "men" } } ; g = M } ; }
- To select values from tables the ! operator is used, to select from records the . operator
- Tuples are special cases of records
1.0.4 Functions
- GF supports both regular functions and anonymous functions
Example:
resource Functions = open Prelude,Predef in { oper succ : Int -> Int; -- Declaration succ i = plus i 1 ; -- Definition succ2 : Int -> Int = -- Declaration \i -> plus i 1; -- Definition }