2013/5/9 John J. Camilleri
Hi all,When writing a resource grammar, I find that having record fields which may be empty is quite a common occurrence. For example, some adjectives in English have a morphological comparative ("happy - happier") while others don't ("expensive - more expensive"). I normally encode this as a string and a boolean, since it is a bad idea to match on the emptiness of the string itself. But this is precisely like the Maybe type in Haskell. So I wrote a resource module which models this.
The Maybe.gf file is attached; below is an example of its use.
I'm surprised no one's done this before actually! Comments are welcome. If you like it, I suggest we include it in the Prelude folder of the RGL.
Abstract
abstract Test = {
cat
A ; N ; Phr ;
fun
caviar_N, pizza_N : N ;
expensive_A, good_A : A ;
more : N -> A -> N -> Phr ;
}
Concrete
concrete TestEng of Test = open Prelude, Maybe in {
lincat
A = {
posit : Str ;
comp : MaybeS
};
N = SS ;
Phr = SS ;
lin
caviar_N = ss "caviar" ;
pizza_N = ss "pizza" ;
expensive_A = {
posit = "expensive" ;
comp = NothingS ;
} ;
good_A = {
posit = "good" ;
comp = JustS "better" ;
} ;
more = \n1,a,n2 ->
let
cmp : Str = fromMaybeS ("more" ++ a.posit) a.comp
in
ss (n1.s ++ "is" ++ cmp ++ "than" ++ n2.s) ;
}
Testing in shell
Test> l more caviar_N good_A pizza_N
caviar is better than pizza
Test> l more caviar_N expensive_A pizza_N
caviar is more expensive than pizza
--
---
You received this message because you are subscribed to the Google Groups "Grammatical Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gf-dev+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.