nikita-volkov / hasql

The fastest PostgreSQL libpq-based driver for Haskell
http://hackage.haskell.org/package/hasql
MIT License
517 stars 54 forks source link

"Short Example" in README fails to compile #120

Closed mcbahson closed 4 years ago

mcbahson commented 4 years ago

I copied the example from the hasql readme and attempted to build, but I received the following:

Main.hs:56:23: error: Operator applied to too few arguments: +
   |
56 |     select $1 :: int8 + $2 :: int8
   |

I'm new to Hasql, so my apologies for not seeing anything obviously wrong.

mcbahson commented 4 years ago

I added {-# LANGUAGE QuasiQuotes #-} to the top of the file and received a new error:

Main.hs:57:39: error:
    • Result expression is missing a typecast
    • In the quasi-quotation:
        [TH.singletonStatement|
    select $1 :: int8 + $2 :: int8
    |]
   |
57 | sumStatement = [TH.singletonStatement|
   |
nikita-volkov commented 4 years ago

You're right! It was a broken example from the beginning! We need to explicitly provide the type for each returned expression:

[TH.singletonStatement| select ($1 :: int8 + $2 :: int8) :: int8 |]
nikita-volkov commented 4 years ago

Fixed the examples