1
0
forked from GitHub/gf-core

introducing multiple inheritance

This commit is contained in:
aarne
2004-09-15 14:36:27 +00:00
parent 9bc8ffe4d1
commit e6fd325d07
44 changed files with 214 additions and 74 deletions

View File

@@ -0,0 +1,7 @@
abstract City = {
cat
City ;
fun
MkCity : String -> City ;
} ;

View File

@@ -0,0 +1,5 @@
concrete CityEng of City = open Prelude in {
lin
MkCity s = s ;
} ;

View File

@@ -0,0 +1,7 @@
abstract Math = {
cat
Number ;
fun
MkNumber : Int -> Number ;
} ;

View File

@@ -0,0 +1,5 @@
concrete MathEng of Math = open Prelude in {
lin
MkNumber i = i ;
} ;

View File

@@ -0,0 +1,4 @@
abstract System = {
cat Reply ;
fun Bye : Reply ;
}

View File

@@ -0,0 +1,4 @@
abstract SystemCity = System, City ** {
fun
RDistance : City -> City -> Int -> Reply ;
} ;

View File

@@ -0,0 +1,6 @@
concrete SystemCityEng of SystemCity = SystemEng, CityEng ** open
Prelude in {
lin
RDistance x y d =
ss (["the distance from"] ++ x.s ++ "to" ++ y.s ++ "is" ++ d.s) ;
} ;

View File

@@ -0,0 +1,3 @@
concrete SystemEng of System = open Prelude in {
lin Bye = ss "bye" ;
}

View File

@@ -0,0 +1,4 @@
abstract SystemMath = System, Math ** {
fun
RSum : Number -> Number -> Int -> Reply ;
} ;

View File

@@ -0,0 +1,6 @@
concrete SystemMathEng of SystemMath = SystemEng, MathEng ** open
Prelude in {
lin
RSum x y d =
ss (["the sum of"] ++ x.s ++ "and" ++ y.s ++ "is" ++ d.s) ;
} ;

7
grammars/multiple/Top.gf Normal file
View File

@@ -0,0 +1,7 @@
abstract Top = User, System ** {
cat
Move ;
fun
MUser : Query -> Move ;
MSystem : Reply -> Move ;
}

View File

@@ -0,0 +1 @@
abstract TopCity = Top, UserCity, SystemCity ** {} ;

View File

@@ -0,0 +1,3 @@
--# -path=.:../prelude
concrete TopCityEng of TopCity = TopEng, UserCityEng, SystemCityEng ** {} ;

View File

@@ -0,0 +1,6 @@
concrete TopEng of Top = UserEng, SystemEng ** open Prelude in {
lin
MUser q = q ;
MSystem r = r ;
}

View File

@@ -0,0 +1 @@
abstract TopMath = Top, UserMath, SystemMath ** {} ;

View File

@@ -0,0 +1,3 @@
--# -path=.:../prelude
concrete TopMathEng of TopMath = TopEng, UserMathEng, SystemMathEng ** {} ;

View File

@@ -0,0 +1,7 @@
abstract User = {
cat
Query ;
fun
QQuit : Query ;
} ;

View File

@@ -0,0 +1,5 @@
abstract UserCity = User, City ** {
fun
QDistance : City -> City -> Query ;
} ;

View File

@@ -0,0 +1,6 @@
concrete UserCityEng of UserCity = UserEng, CityEng ** open Prelude in
{
lin
QDistance x y = ss (["what is the distance from"] ++ x.s ++ "to" ++ y.s) ;
}

View File

@@ -0,0 +1,5 @@
concrete UserEng of User = open Prelude in {
lin
QQuit = ss ["that's enough"] ;
} ;

View File

@@ -0,0 +1,5 @@
abstract UserMath = User, Math ** {
fun
QSum : Number -> Number -> Query ;
} ;

View File

@@ -0,0 +1,6 @@
concrete UserMathEng of UserMath = UserEng, MathEng ** open Prelude in
{
lin
QSum x y = ss (["what is the sum of"] ++ x.s ++ "and" ++ y.s) ;
}

View File

@@ -0,0 +1 @@
abstract UserUnionCity = union User, City ;

32
grammars/multiple/map.txt Normal file
View File

@@ -0,0 +1,32 @@
Using multiple inheritance in GF. AR 15/9/2004.
The following diagrams show inheritance between abstract syntaxes in two simple systems.
TopCity
/ | \
/ | \
SystemCity UserCity Top
/ \ / \
System City User
TopMath
/ | \
/ | \
SystemMath UserMath Top
/ \ / \
System Math User
Idea of each module:
User -- User's moves on any domain
System -- System's moves on any domain
Top -- grammar covering both kinds of moves
X = Math, City -- possible domains
UserX -- User's domain specific moves
SystemX -- System's domain specific moves
TopX -- all moves on the domain X
In parallel to the abstract syntax hierarchies, we have of course
hierarchies of concrete syntaxes for any language; this directory contains Eng.