zmactep / hasbolt

Haskell driver for Neo4j 3+ (BOLT protocol)
BSD 3-Clause "New" or "Revised" License
82 stars 13 forks source link

error: Variable not in scope: def #12

Closed robmoore-i closed 5 years ago

robmoore-i commented 5 years ago

Hi, thanks for making this. I can't seem to access the 'def' function. I've installed using cabal install hasbolt.

$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Prelude> import Database.Bolt
Prelude Database.Bolt> pipe <- connect $ def { user = "neo4j", password = "xxxxx" }

<interactive>:2:19: error: Variable not in scope: def :: BoltCfg

<interactive>:2:32: error:
    • Couldn't match expected type ‘Data.Text.Internal.Text’
                  with actual type ‘[Char]’
    • In the ‘user’ field of a record
      In the second argument of ‘($)’, namely
        ‘def {user = "neo4j", password = "zuhlke"}’
      In the first argument of ‘GHC.GHCi.ghciStepIO ::
                                  forall a. IO a -> IO a’, namely
        ‘connect $ def {user = "neo4j", password = "zuhlke"}’

<interactive>:2:52: error:
    • Couldn't match expected type ‘Data.Text.Internal.Text’
                  with actual type ‘[Char]’
    • In the ‘password’ field of a record
      In the second argument of ‘($)’, namely
        ‘def {user = "neo4j", password = "zuhlke"}’
      In the first argument of ‘GHC.GHCi.ghciStepIO ::
                                  forall a. IO a -> IO a’, namely
        ‘connect $ def {user = "neo4j", password = "zuhlke"}’
Prelude Database.Bolt> [Ctrl-D]
Leaving GHCi.
$ 

Cheers,

Rob

ozzzzz commented 5 years ago

Hi, Rob!

def function is in Data.Default module.

Use > import Data.Default.

Cheers,

Bogdan

ozzzzz commented 5 years ago

Ah, and also add extension OverloadedStrings with :set -XOverloadedStrings.

Here is minimal example for you:

> import Database.Bolt
> import Data.Default
> :set -XOverloadedStrings
> let config = def {user = "neo4j", password = "xxx"} :: BoltCfg
> connection <- connect config
> myQuery = query "create (n:Event {name: \"fprog meetup\"}) return n"
> run connection myQuery
[fromList [("n",S (Structure {signature = 78, fields = [I 21,L [T "Event"],M (fromList [("name",T "fprog meetup")])]}))]]
zmactep commented 5 years ago

Thanks, @ozzzzz!

Yes, everything is right. The same was already discussed here.