mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-11-28 22:24:49 +03:00
add helloworld examples for LTS-9 and LTS-8.
This commit is contained in:
parent
ac93fcea7b
commit
178502f7e5
24
helloworld-8.md
Normal file
24
helloworld-8.md
Normal 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
24
helloworld-9.md
Normal 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 %}
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user