haskell-relational-record/helloworld-8.md
2018-02-25 16:48:33 +09:00

25 lines
645 B
Markdown

### 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 %}