add helloworld examples for LTS-9 and LTS-8.

This commit is contained in:
Kei Hibino 2018-02-25 16:48:33 +09:00
parent ac93fcea7b
commit 178502f7e5
3 changed files with 52 additions and 0 deletions

24
helloworld-8.md Normal file
View File

@ -0,0 +1,24 @@
### Composing relations (for LTS-8)
Copy the following to "helloworld.hs" for LTS-8:
{% highlight haskell %}
import Database.Relational.Query
import Data.Int (Int32)
hello :: Relation () (Int32, String)
hello = relation $ return (value 0 >< value "Hello")
world :: Relation () (Int32, String)
world = relation $ return (value 0 >< value "World!")
helloWorld :: Relation () ((Int32, String), String)
helloWorld = relation $ do
h <- query hello
w <- query world
on $ h ! fst' .=. w ! fst'
return $ (,) |$| ((,) |$| h ! fst' |*| h ! snd') |*| w ! snd'
main :: IO ()
main = putStrLn $ show helloWorld ++ ";"
{% endhighlight %}

24
helloworld-9.md Normal file
View File

@ -0,0 +1,24 @@
### Composing relations (for LTS-9)
Copy the following to "helloworld.hs" for LTS-9:
{% highlight haskell %}
import Database.Relational.Query
import Data.Int (Int32)
hello :: Relation () (Int32, String)
hello = relation $ return (value 0 >< value "Hello")
world :: Relation () (Int32, String)
world = relation $ return (value 0 >< value "World!")
helloWorld :: Relation () (Int32, String, String)
helloWorld = relation $ do
h <- query hello
w <- query world
on $ h ! fst' .=. w ! fst'
return $ (,,) |$| h ! fst' |*| h ! snd' |*| w ! snd'
main :: IO ()
main = putStrLn $ show helloWorld ++ ";"
{% endhighlight %}

View File

@ -109,6 +109,10 @@ main :: IO ()
main = putStrLn $ show helloWorld ++ ";"
{% endhighlight %}
(You may use older LTS. Please check
[LTS-9 - helloworld.hs](helloworld-9.html) or
[LTS-8 - helloworld.hs](helloworld-8.html).)
This code defines queries called `hello` and `world`. And `helloworld` composes them by joining them on the first element of the tuples.
This code generates the following SQL statement: