Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deriving Generic doesn't work even though DeriveGeneric is on

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
like image 876
theduke Avatar asked Mar 06 '23 05:03

theduke


1 Answers

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

like image 121
luqui Avatar answered Mar 08 '23 18:03

luqui