gpt4 book ai didi

haskell - 即使 DeriveGeneric 打开,派生 Generic 也不起作用

转载 作者:行者123 更新时间:2023-12-02 18:30:45 30 4
gpt4 key购买 nike

我正在尝试遵循 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 语言编译指示。

我在这里缺少什么?

构建环境:

  • 堆栈 lts-11.9
  • Linux

最佳答案

{-# LANGUAGE #-} 声明需要位于文件的最顶部,位于 module 声明之前。

关于haskell - 即使 DeriveGeneric 打开,派生 Generic 也不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50314032/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com