This code is compiled fine:
data None = None { _f :: Int }
type Simpl = Env
type Env = Int
Run Code Online (Sandbox Code Playgroud)
However, I got an error with this code:
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data None = None { _f :: Int }
type Simpl = Env
makeLenses ''None
type Env = Int
Run Code Online (Sandbox Code Playgroud)
Error:
Not in scope: type constructor or class `Env'
Run Code Online (Sandbox Code Playgroud)
I just added a single line makeLenses ''None between type declarations.
This means TemplateHaskell code could …
我想使用镜头和可扩展效果来做一个简单的例子.
错误消息说类型是不明确的,因为带有参数的类型类HasObj x和GHC无法理解pos从哪里来,我猜.
makeClassy使用通用数据函数定义抽象数据类型非常有用,因此在我的实际项目中需要它.
我的问题是:我怎样才能让它发挥作用?
或者,有没有办法从数据类型定义镜头并在Eff.State中使用它们?
{-# LANGUAGE TemplateHaskell, TypeOperators, DeriveDataTypeable #-}
import Control.Eff
import Control.Eff.Lift
import Control.Eff.State.Strict
import Control.Lens hiding (use, (%=), (.=))
import Control.Monad
import Data.Typeable
-- define data types
data Obj = Obj { _pos :: Int } deriving (Show)
data Person = Person {
_objPerson :: Obj,
_greeting :: String
} deriving (Show, Typeable)
-- make typeclasses and lenses
makeClassy ''Obj
makeLenses ''Person
instance HasObj Person where …Run Code Online (Sandbox Code Playgroud)