Overview of Grakn Haskell Driver

Grakn Haskell Client


To install the Grakn client, simply add this to your cabal file:

build-depends: grakn

You will also need access to a Grakn database. Head here to see how to set up a Grakn database.


Begin by importing the client:

{-# LANGUAGE OverloadedStrings #-}

module Example where

import Grakn

import Data.Function ((&))

Define the type labels:

person :: Label
person = label "person"

husband :: Label
husband = label "husband"

wife :: Label
wife = label "wife"

marriage :: Label
marriage = label "marriage"

Define the variables:

x :: Var
x = var "x"

y :: Var
y = var "y"

We can translate the following query into Haskell:

match $x isa person; (husband: $x, wife: $y) isa marriage; get $y;
query :: GetQuery
query = match
    [ x `isa` person
    , rel [husband .: x, wife .: y] `isa` marriage
    ] & get [y]

We can also use infix functions like (-:) instead of isa:

otherQuery :: GetQuery
otherQuery = match
    [ x -: person
    , rel [husband .: x, wife .: y] -: marriage
    ] & get [y]

To execute and print the results of our query:

client :: Client
client = Client defaultUrl "my-keyspace"

main :: IO ()
main = do
    result <- execute client query
    print result