我想学习如何使用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镜头的实用介绍,其中包含简单的用法示例和尽可能少的类别理论?
:{
data Point = Point { _x :: Double, _y :: Double } deriving (Show)
data Atom = Atom { _element :: String, _point :: Point } deriving (Show)
makeLenses ''Point
:}