Haskell: makeLenses - 数据构造函数不在范围内
Haskell: makeLenses - data constructor not in scope
我这里有这个简单的代码来定义类型并使用 makeLenses
生成镜头。
module Api.Jira.Types.Search
(
SearchRequest(..)
) where
import GHC.Generics
import qualified Data.Text as T
import Data.Aeson (FromJSON, ToJSON)
import Control.Lens
import Data.Aeson
import Data.Aeson.Types
data SearchRequest = SearchRequest
{ _jql :: T.Text
, _startAt :: Maybe Int
, _maxResults :: Maybe Int
, _fields :: Maybe [T.Text]
, _expand :: Maybe [T.Text]
, _properties :: Maybe [T.Text]
} deriving (Show, Generic)
instance ToJSON SearchRequest where
toJSON = genericToJSON defaultOptions {
fieldLabelModifier = drop 1 }
instance FromJSON SearchRequest where
parseJSON = genericParseJSON defaultOptions {
fieldLabelModifier = drop 1 }
makeLenses SearchRequest''
这会导致错误:
Data constructor not in scope:
SearchRequest''
:: template-haskell-2.11.1.0:Language.Haskell.TH.Syntax.Name
• Perhaps you meant one of these:
‘SearchRequest’ (line 20), variable ‘searchRequest’ (line 39)
我在 SO 上发现了两个有点相关的问题,但它们与声明顺序有关并且似乎不适用于此处,因为 SearchRequest
中包含的所有类型都已定义。
- Haskell: Template Haskell and the scope
知道是什么原因造成的吗?
是''SearchRequest
,不是SearchRequest''
。
我这里有这个简单的代码来定义类型并使用 makeLenses
生成镜头。
module Api.Jira.Types.Search
(
SearchRequest(..)
) where
import GHC.Generics
import qualified Data.Text as T
import Data.Aeson (FromJSON, ToJSON)
import Control.Lens
import Data.Aeson
import Data.Aeson.Types
data SearchRequest = SearchRequest
{ _jql :: T.Text
, _startAt :: Maybe Int
, _maxResults :: Maybe Int
, _fields :: Maybe [T.Text]
, _expand :: Maybe [T.Text]
, _properties :: Maybe [T.Text]
} deriving (Show, Generic)
instance ToJSON SearchRequest where
toJSON = genericToJSON defaultOptions {
fieldLabelModifier = drop 1 }
instance FromJSON SearchRequest where
parseJSON = genericParseJSON defaultOptions {
fieldLabelModifier = drop 1 }
makeLenses SearchRequest''
这会导致错误:
Data constructor not in scope: SearchRequest'' :: template-haskell-2.11.1.0:Language.Haskell.TH.Syntax.Name • Perhaps you meant one of these: ‘SearchRequest’ (line 20), variable ‘searchRequest’ (line 39)
我在 SO 上发现了两个有点相关的问题,但它们与声明顺序有关并且似乎不适用于此处,因为 SearchRequest
中包含的所有类型都已定义。
- Haskell: Template Haskell and the scope
知道是什么原因造成的吗?
是''SearchRequest
,不是SearchRequest''
。