Skip to content

Instantly share code, notes, and snippets.

@inariksit
Last active March 31, 2022 02:54
Show Gist options
  • Save inariksit/0f9902873d18068a477e96ddd71f6561 to your computer and use it in GitHub Desktop.
Save inariksit/0f9902873d18068a477e96ddd71f6561 to your computer and use it in GitHub Desktop.
Different strategies of getting around the lack of ConjUtt. The first pair (TestConj, TestConjEng) adds a list instance of our own custom type, with lincat Utt. The second pair (TestConjHack, TestConjHackEng) shows two different workarounds, if you can't be bothered with adding a list instance for your cats. The hacky version relies on the fact …
abstract TestConj = {
-- Same as the hacky version until the list instance
flags startcat = MyUtt ;
cat
MyUtt ; MyCl ;
fun
testUtt : MyUtt ;
testCl : MyCl ;
conjDifferentTypes : MyCl -> MyUtt -> MyUtt ;
-- Here we add a list instance for MyUtt + some other convenience cats and funs
cat
[MyUtt]{2} ;
MyConj ;
fun
-- BaseMyUtt, ConsMyUtt are generated automatically from [MyUtt]{2}
-- We only need to write explicit linearisation for them, not add to abstract
-- However, we add the following convenience fun, to mimic the RGL structure
ConjMyUtt : MyConj -> [MyUtt] -> MyUtt ;
}
-- The non-hacky version: we actually add a list instance for MyUtt
concrete TestConjEng of TestConj =
open Prelude, Coordination,
SyntaxEng, LexiconEng in {
-----------------------------------------------------------------------------------------
-- Just like in the hacky version: lincats and test lexicon
lincat
MyUtt = Utt ;
MyCl = Cl ;
lin
testUtt = yes_Utt ;
testCl = mkCl somebody_NP sleep_V ;
-----------------------------------------------------------------------------------------
-- Lincat for [MyUtt] + lins for the automatically generated BaseMyUtt and ConsMyUtt
-- We implement these using the generic opers from prelude/Coordination.gf,
-- https://github.com/GrammaticalFramework/gf-rgl/blob/master/src/prelude/Coordination.gf
lincat
[MyUtt] = Coordination.ListX ;
MyConj = Conj ;
lin
-- MyUtt -> MyUtt -> [MyUtt] ;
BaseMyUtt u1 u2 = Coordination.twoSS u1 u2 ;
-- MyUtt -> [MyUtt] -> [MyUtt] ;
ConsMyUtt u us = Coordination.consrSS "," u us ;
-- : MyConj -> [MyUtt] -> MyUtt ;
ConjMyUtt conj utts = Coordination.conjunctDistrSS conj utts ;
-----------------------------------------------------------------------------------------
-- Finally, implementing conjDifferentTypes is just like any RGL category
lin
-- : MyCl -> MyUtt -> MyUtt ;
conjDifferentTypes cl utt = ConjMyUtt and_Conj (BaseMyUtt (mkUtt cl) utt) ;
}
abstract TestConjHack = {
flags startcat = MyUtt ;
cat
MyUtt ; MyCl ;
fun
testUtt : MyUtt ;
testCl : MyCl ;
conjDifferentTypes1,
conjDifferentTypes2,
conjDifferentTypes3 : MyCl -> MyUtt -> MyUtt ;
}
concrete TestConjHackEng of TestConj =
open Prelude, Coordination, -- for low-level opers
SyntaxEng, LexiconEng in {
lincat
MyUtt = Utt ;
MyCl = Cl ;
lin
testUtt = yes_Utt ;
testCl = mkCl somebody_NP sleep_V ;
-- : MyCl -> MyUtt -> MyUtt ;
-- Different strategies of hacking a conj between Utt and Cl
-- 1) Explicit coercions inside the function, using mkAdv : Conj -> Adv -> Adv -> Adv
conjDifferentTypes1 cl utt =
let clUtt : Utt = mkUtt cl ; -- need this step, with <mkUtt cl : Adv> it complains
fakeAdv : Adv =
mkAdv and_Conj
<clUtt : Adv> -- temporarily fooling mkAdv that its Utt args are, in fact, Advs
<utt : Adv> ;
in lin Utt fakeAdv ; -- need to convert the fakeAdv back into Utt
-- <fakeAdv : Utt> is not enough here, it's just for temporary deception
-- here we need to really make fakeAdv back into Utt, so lin Utt is needed
-- 2) Like previous, but using the super low-level opers from https://github.com/GrammaticalFramework/gf-rgl/blob/master/src/prelude/Coordination.gf
conjDifferentTypes2 cl utt =
let clUtt : Utt = mkUtt cl ;
listUtt : ListX = twoSS clUtt utt ; -- ListX and twoSS are from Coordination.
-- they operate on pure {s : Str}, no lock fields.
-- So every RGL category C, with lincat {s : Str}, is a subtype of SS.
-- Likewise, every ListC for such C is a subtype of ListX.
-- Hence, we can use twoSS and other such opers without any <foo : Bar>.
cl_and_utt : SS =
conjunctDistrSS and_Conj listUtt ; -- and_Conj, of RGL category Conj, is a subtype of the type Conjunction from Coordination.gf.
in lin Utt cl_and_utt ; -- Still need to convert the SS back into Utt though.
-- 3) Using an oper for Conj -> Utt -> Utt -> Utt
conjDifferentTypes3 cl utt = conjUtt and_Conj (mkUtt cl) utt ;
oper
-- An oper to hide the details of this hack. You may use any of the strategies in 1) or 2).
conjUtt : Conj -> Utt -> Utt -> Utt ;
conjUtt c u1 u2 = lin Utt {s = "TODO: actual implementation"} ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment