Created
December 4, 2018 10:02
-
-
Save lierdakil/16c2520a08ba6167629eebe483faf786 to your computer and use it in GitHub Desktop.
Example of TutorialD quasiquoter syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveGeneric, DeriveAnyClass, OverloadedStrings, QuasiQuotes, TemplateHaskell #-} | |
module Main where | |
import ProjectM36.Client | |
import ProjectM36.Relation.Show.Term | |
import GHC.Generics | |
import Data.Text | |
import Data.Binary | |
import Control.DeepSeq | |
import qualified Data.Map as M | |
import qualified Data.Text.IO as TIO | |
import Data.Proxy | |
import TutorialD.QQ | |
data Hair = Bald | Brown | Blond | OtherColor Text | |
deriving (Generic, Show, Eq, Binary, NFData, Atomable) | |
main :: IO () | |
main = do | |
--connect to the database | |
let connInfo = InProcessConnectionInfo NoPersistence emptyNotificationCallback [] | |
eCheck v = do | |
x <- v | |
case x of | |
Left err -> error (show err) | |
Right x' -> pure x' | |
conn <- eCheck $ connectProjectM36 connInfo | |
--create a database session at the default branch of the fresh database | |
sessionId <- eCheck $ createSessionAtHead conn "master" | |
--create the data type in the database context | |
eCheck $ executeDatabaseContextExpr sessionId conn (toAddTypeExpr (Proxy :: Proxy Hair)) | |
--create a relation with the new Hair AtomType | |
let blond = Blond | |
grey = OtherColor "Grey" | |
eCheck $ executeDatabaseContextExpr sessionId conn | |
[tutdctx|people := relation{ | |
tuple{hair $blond, name "Colin"}, | |
tuple{hair $grey, name "Greg"} | |
}|] | |
peopleRel <- eCheck $ executeRelationalExpr sessionId conn | |
[tutdrel|people where hair = $grey|] | |
TIO.putStrLn (showRelation peopleRel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment