| ID | a7e4d5dc-cb74-4d71-bc87-23b4eabd1f08 |
|---|---|
| ROAM_ALIASES | "GF (programming language)" |
| DEERTOPIAVISIBILITY | public |
Grammatical Framework
Grammatical Framework (GF) is a functional programming language specialised for linguistics.
Inbox
One of the key ideas in multilingual grammars is that an abstract syntax need not care about features like morphology, agreement, word order, and discontinuity. The abstract syntax is, to use linguistic terminology, purely about constituency: it tells what the constituents— that is, significant parts—of an expression are, without telling what they exactly look like or what their linear order is.
Expressiveness of grammars
- BNF
what we have for describing programming languages
- string-based grammar
what we have when all linearisation types are strings (doesn't permit complex morphology).
- GF
really powerful lol
- definite clause grammar
something about prolog
- unification grammar
something about prolog again (and parameters)
Tables vs. functions
The domain of a table must be a parameter type, ensuring the table represents a finite set of pairs.
Declarations
funandlinare abstract and concrete grammatical constructs. kinda like data constructors.catandlincatare abstract and concrete typesoperis for normal functions (called operations).
Pattern macros
GF has pattern macros, similar to Haskell's pattern synonyms.[cite:@ranta2004grammatical]
vowel : pattern Str
= #("a" | "e" | "i" | "o" | "u" | "y") ;
vowelFinal : Str -> Str
= \s -> case s of {
xs + #vowel => "Ends in vowel" ;
_ => "Ends in consonant"
} ;
Pattern macros can be paramaterised, but unfortunately seem to be limited in that they cannot be used inline in case-expressions, thus preventing variable bindings and such.
-- Example per Inari Listenmaa on the GF Discord.
oper
foo : pattern Str = #("foo"|"FOO"|"Foo") ;
bar : pattern Str = #("bar"|"BAR"|"Bar") ;
commaSeparated : (x,y : pattern Str) -> pattern Str
= \x,y -> #(x + "," + y) ;
foobar : pattern Str = commaSeparated foo bar ;
-- If not using function, need to include the #
-- foobar : pattern Str = #(#foo + "," + #bar) ;
test : Str -> Str = \s -> case s of {
#foobar => s ++ "matched the pattern made of subpatterns!" ;
_ => s ++ "did not match"
} ;
References
[cite:@ranta2004grammatical]