GHC Language
>>GHC Syntax
H :- G1, G2, . . ., Gn | B1, B2, . . ., Bm.
- Above form is called a "clause"
- H is "head", H and G form "guard" and B is "body"
- H, G, B are predicates
- ex.1: true
- ex.2: copy(Xs, Ys)
- G, B are also called "goals"
- List expression:
- [a|b] and [a, b] are syntactic sugars for
cons(a, b) and
cons(a, cons(b, nil)),
respectively
- Symbols starting with a capital letter or '_' are variables
- A variable namded '_' is an anonymous variable
- Multiple anonymous variables in a clause are all unique
>>GHC Execution Model
- Execution of a GHC program is to replace goals
- Goals separated by ',' are executed concurrently
- If the pattern of a goal matches a head, the guard of the
clause is tried
- Upon which variables may be instantiated only if they
are not from calling side
- Trial is done concurrently
- Chooses just one clause whose guard has succeeded,
and replaces the original goal by the body
- Body goals may instantiate variables from the calling side
GHC is a simple language, as execution models of languages are not usually
described as short as above.