Page 1

Implementing web applications using GF

Page 2

Server-side GF applications

Page 3
Server-side GF applications

Implementation: server side

Page 4
Server-side GF applications

Implementation: client side

Some HMTL+JavaScript to submit questions and embed the answer in the same web page

Page 5

Installing the PGF run-time library

Page 6

Applications in other languages

Page 7

Application programming with GF grammars

Haskell API & Examples

Page 8

Haskell Applications

PGF run-time library

Page 9

Example 1: a simple translator

Translator.hs

Page 10

Example 2: a question-answering system

Page 11
Example 2: a question-answering system

Abstract syntax in GF

abstract Arithmetic = {
    
flags startcat=Question ;

cat Answer; Object; Question;

fun Even, Odd, Prime : Object -> Question;
    Number : Int -> Object;

    Yes, No : Answer;
}
Page 12
Example 2: a question-answering system

Concrete syntax for English

concrete ArithmeticEng of Arithmetic = {

lincat
    Answer, Object, Question = Str;

lin Even object = is "even" object;
    Odd object = is "odd" object;
    Prime object = is "prime" object;
    Number int = int.s;
    No  = "No.";
    Yes  = "Yes.";

oper is : Str -> Str -> Str  = \ pred,obj -> "is"++obj++pred++"?";
}
Page 13
Example 2: a question-answering system

Haskell code

Similar to the translator example, but

Page 14
Example 2: a question-answering system → Haskell code
Page 15
Example 2: a question-answering system

Exporting GF abstract syntax to Haskell

Page 16
Example 2: a question-answering system

Generated Haskell Code

Page 17
Example 2: a question-answering system

Transfer function

Page 18
Example 2: a question-answering system → Transfer function

Compile with:
ghc --make Answer.hs

Page 19

Example 3

A larger query language

Grammar: Query.gf, MathQuery.gf, QueryEng.gf, MathQueryEng.gf