Haskell,Control.Lens:无法将类型“ [[Language.Haskell.TH.Syntax.Dec]””与“ Language.Haskell.TH.Syntax.Exp”

问题描述 投票:1回答:1

我想学习如何使用Control.Lens软件包。我尝试使用an official tutorial

首先,我没有Control.Lens.Tutorial软件包。重现示例是否重要?

我启动了GHCi并加载了TemplateHaskell扩展名:

Prelude> :set -XTemplateHaskell

然后我尝试重现本教程的第一步:

Prelude> import Control.Lens hiding (element)
Prelude Control.Lens> import Control.Lens.TH
Prelude Control.Lens Control.Lens.TH> 
Prelude Control.Lens Control.Lens.TH> data Point = Point { _x :: Double, _y :: Double } deriving (Show)
Prelude Control.Lens Control.Lens.TH> data Atom = Atom { _element :: String, _point :: Point } deriving (Show)
Prelude Control.Lens Control.Lens.TH> $(makeLenses ''Point)

出现错误:

<interactive>:7:3: error:
    • Couldn't match type ‘[Language.Haskell.TH.Syntax.Dec]’
                     with ‘Language.Haskell.TH.Syntax.Exp’
      Expected type: Language.Haskell.TH.Lib.Internal.ExpQ
        Actual type: Language.Haskell.TH.Lib.Internal.DecsQ
    • In the expression: makeLenses ''Point
      In the untyped splice: $(makeLenses ''Point)

GHC 8.6.4,从Cabal安装镜头4.19.2。

该教程有点过时了吗?如果是,我在哪里可以阅读Haskell镜头的实用介绍,其中包含简单的用法示例和尽可能少的类别理论?

haskell lens template-haskell
1个回答
1
投票

  :{
  data Point = Point { _x :: Double, _y :: Double } deriving (Show)
  data Atom = Atom { _element :: String, _point :: Point } deriving (Show)
  makeLenses ''Point
  :}

© www.soinside.com 2019 - 2024. All rights reserved.