deriving Generic doesn't work even though DeriveGeneric is on

余生颓废 提交于 2019-12-10 16:18:27

问题


I'm trying to follow the tutorial for the Beam Haskell library: 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"

This results in the following error:

    • 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
   |              ^^^^^^^

Note that the DeriveGeneric language pragma is present.

What am I missing here?

Build environment:

  • stack lts-11.9
  • Linux

回答1:


A {-# LANGUAGE #-} declaration needs to go at the very top of the file, before the module declaration.



来源:https://stackoverflow.com/questions/50314032/deriving-generic-doesnt-work-even-though-derivegeneric-is-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!