latka a language for random text generation
play

Latka: A Language for Random Text Generation Getty D. Ritter POPL - PowerPoint PPT Presentation

Latka: A Language for Random Text Generation Getty D. Ritter POPL OBT Jan 25, 2014 Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT Jan 25, 2014 1 / 23 Background: Roguelikes Figure : Brogue c 2012 Brian Walker


  1. Latka: A Language for Random Text Generation Getty D. Ritter POPL OBT — Jan 25, 2014 Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 1 / 23

  2. Background: Roguelikes Figure : Brogue c � 2012 Brian Walker Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 2 / 23

  3. Background: Roguelikes Figure : Dwarf Fortress c � 2002-2012 Tarn Adams Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 3 / 23

  4. Lord Tiahaki’ne This is Lord Tiahaki’ne, an Elder of the Kute’aha. Its carapace is mottled and it wears fine jewelry of gold and pearls. Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 4 / 23

  5. Hatchling Wipa’a This is Wipa’a, a Hatchling of the Kute’aha. It has just been born to Peko, just one of 133 siblings. Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 5 / 23

  6. Two Basic Problems 1 Concisely and reliably express a nondeterministic set of strings for human consumption. 2 Provide primitives appropriate to constructing text at a higher level than string concatenation. Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 6 / 23

  7. Solution Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 7 / 23

  8. Solution Write an embedded DSL for an existing language. Don’t reinvent the wheel. description :: StringChoiceM () description = chooseRole >>= \ case Lord -> do name <- genName appr <- genAppearance ... Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 8 / 23

  9. More Entertaining Solution Because reinventing the wheel is fun: the Latka language. Embed probabalistic choice as an effect, and select primitive operations appropriate to the problem domain. consonant = "p" | "t" | "k" | "w" | "h" | "m" | "n" vowel = ("a" | "e" | "i" | "o" | "u") (4: "" | "’") syllable = 4: consonant vowel | vowel word = (4 | 5 | 6) @ syll puts word { - kinane, hupitu’, wuteni, newai, - puwupo, kuikia, teipi’, ituwoi, - kaekupu, ikukukiepa’, henewu, topano - } Getty D. Ritter Latka: A Language for Random Text GenerationPOPL OBT — Jan 25, 2014 9 / 23

  10. Latka Command Language A single command, only available at the top-level: puts "Hello, World!" Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 10 / 23

  11. Latka Expression Language Basic choice and string concatenation: a = "this" "that" "whatever" -- a evaluates to "thisthatwhatever" b = "this" | "that" | "whatever" -- b evaluates to "this" or "that" or "whatever" c = 9: "this" | "that" -- c evalutes to "this" nine times out of ten d = (8 @ "na") " batman" -- d evaluates to exactly what you’d expect Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 11 / 23

  12. Latka Expression Language . . . with a dash of generic-strongly-typed-functional-language: data Maybe t = Just t | Nothing foo : Maybe (String * String) -> String foo x = case x of Just.p -> "(" fst.p "," snd.p ")" Nothing -> "()" The f.x syntax for function application is borrowed from Dijkstra. f.x.y == (f.x).y Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 12 / 23

  13. Latka Expression Language Expressions are typically call-by-name cbn = let x = "a" | "b" in x x -- { "aa", "ab", "ba", "bb" } But you can force call-by-value by using the fixed keyword cbv = let fixed x = "a" | "b" in x x -- { "aa", "bb" } Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 13 / 23

  14. Latka Expression Language This is necessary for long text descriptions: let gender = Female | Male | Other in "A " noun.gender " stands nearby. " "You approach " objpronoun.gender "." A man stands nearby. You approach him. A person stands nearby. You approach them. Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 14 / 23

  15. Latka Expression Language This is necessary for long text descriptions: let gender = Female | Male | Other in "A " noun.gender " stands nearby. " "You approach " objpronoun.gender "." A man stands nearby. You approach her. A woman stands nearby. You approach him. Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 15 / 23

  16. Latka Expression Language This is necessary for long text descriptions: let fixed gender = Female | Male | Other in "A " noun.gender " stands nearby. " "You approach " objpronoun.gender "." A woman stands nearby. You approach her. A person stands nearby. You approach them. Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 16 / 23

  17. Static Guarantees Strongly typed with type inference and optional type annotations. Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 17 / 23

  18. Static Guarantees Strongly typed with type inference and optional type annotations. Latka also only allows structural recursion. Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 17 / 23

  19. Static Guarantees Strongly typed with type inference and optional type annotations. Latka also only allows structural recursion. Consequently, Latka programs by construction cannot go wrong. Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 17 / 23

  20. Latka Type System Unremarkable, save a single experimental feature: Var a is a type of arbitrary-length tuples of types convertible to a . The only valid operation on Var a is fgt : Var a -> List a Var a can only appear in negative position in an arrow type. Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 18 / 23

  21. Latka Type System A lot of work for relatively little benefit: listAll : Var String -> String listAll v = let go.[] = "nothing." go.[x] = x "." go.[x,y] = x " and " y "." go (x::xs) = x ", " go xs in go.(fgt.v) Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 19 / 23

  22. Latka Type System But still a small convenience: puts listAll.() -- "nothing." puts listAll.(2,True,"blue") -- "2, True and blue." puts listAll.(5, \ x -> x) -- compile-time error, can’t convert (a -> a) to String Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 20 / 23

  23. Latka Standard Library Still a work-in-progress, but crucially must provide intelligent primitives for constructing human language, e.g. for creating sentences, words, proper nouns, &c puts se.( "one two" , wd."three" , pn."four" ) -- "One two three Four." puts pa.( lst.( "one", "two" ) ) -- " One, two." Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 21 / 23

  24. The Future of Latka Compile to a “reasonable” target Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 22 / 23

  25. The Future of Latka Compile to a “reasonable” target Refine the human-language API Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 22 / 23

  26. The Future of Latka Compile to a “reasonable” target Refine the human-language API Explore what constitutes a useful standard library (e.g. Language.Natural.Latin ) Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 22 / 23

  27. The Future of Latka Compile to a “reasonable” target Refine the human-language API Explore what constitutes a useful standard library (e.g. Language.Natural.Latin ) Use Latka to produce data other than text Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 22 / 23

  28. And So Forth data Rank = Hatchling | Elder carapaceColor : String carapaceColor = "mottled" | "yellow" | "red" | "black" descriptionFor : Rank -> String -> Para descriptionFor.Hatchling.name = pa.( se.( "This is ", name , ", a Hatchling of the Kute’aha" ) , ( se.( "It will ", "soon" | "eventually" , "graduate and become an adult" ) | se.( "It has just been born to" , kuteahaName, "and has" , 1d200, "siblings" ) ) ) descriptionFor.Elder.name = ... Getty D. Ritter Latka: A Language for Random Text Generation POPL OBT — Jan 25, 2014 23 / 23

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend