Misleading GHC error when function is not in scope
Let's assume we have the following code compiled with GHC-8.6.3:
#!/usr/bin/env cabal
{- cabal:
build-depends:
, base ^>= 4.12.0.0
, generics-sop ^>= 0.3.2.0
, squeal-postgresql == 0.4.0.0
ghc-options:
-Wall
-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
import GHC.Generics (Generic)
import Squeal.PostgreSQL ((:::), Definition, Enumerated, PG, SchemumType (Typedef))
import qualified Generics.SOP.Universe as Sop
main :: IO ()
main = putStrLn "Hello"
data Status = Ok | NotOk
deriving instance Generic Status
instance Sop.Generic Status
instance Sop.HasDatatypeInfo Status
type Schema = '[ "enumStatus" ::: 'Typedef (PG (Enumerated Status)) ]
setupDb :: Definition '[] Schema
setupDb = createTypeEnumFrom @Status #enumStatus
When I run this script the error says:
Main.hs:35:11: error:
• Cannot apply expression of type ‘t1’
to a visible type argument ‘Status’
• In the expression: createTypeEnumFrom @Status #enumStatus
In an equation for ‘setupDb’:
setupDb = createTypeEnumFrom @Status #enumStatus
|
35 | setupDb = createTypeEnumFrom @Status #enumStatus
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Though this issue is resolved by adding createTypeEnumFrom
to the import list of the Squeal.PostgreSQL
module.
My feeling is that the error text is a bit misleading (it took me a while to find the reason in the real project). And also my understanding was that first the compiler should scan the scope and let us know if any functions are out of the scope for this module.