即使DeriveGeneric已启用,派生Generic也不起作用

时间:2018-05-13 08:05:10

标签: haskell generics haskell-stack

我正在尝试使用Beam Haskell库的教程:https://tathougies.github.io/beam/tutorials/tutorial1/

module Lib
    ( someFunc
    ) where

{-# LANGUAGE
    DeriveGeneric
  , GADTs
  , OverloadedStrings
  , FlexibleContexts
  , FlexibleInstances
  , TypeFamilies
  , TypeApplications
 #-}

import Database.Beam
import Database.Beam.Postgres
import GHC.Generics

import Data.Text (Text)

data UserT f
    = User
    { _userEmail     :: Columnar f Text
    , _userFirstName :: Columnar f Text
    , _userLastName  :: Columnar f Text
    , _userPassword  :: Columnar f Text }
    deriving Generic

someFunc :: IO ()
someFunc = putStrLn "someFunc"

这会导致以下错误:

    • Can't make a derived instance of ‘Generic (UserT f)’:
        You need DeriveGeneric to derive an instance for this class
    • In the data declaration for ‘UserT’
   |
27 |     deriving Generic
   |              ^^^^^^^

请注意,DeriveGeneric语言编译指示存在。

我在这里缺少什么?

构建环境:

  • stack lts-11.9
  • 的Linux

1 个答案:

答案 0 :(得分:7)

{-# LANGUAGE #-}声明之前,module声明需要放在文件的最顶层。