我想使用字符串文字作为遍历,但我有点迷失在类型上。是否可以创建此实例?
import Control.Lens
import Data.Aeson
import Data.Aeson.Lens
import Data.String
import Data.Default
{- Having:
key' :: AsValue t => Text -> Traversal' t (Maybe Value)
_JSON :: (ToJSON a, FromJSON a) => Traversal' t a
-}
instance (AsValue t, FromJSON v, ToJSON v, Default v) => IsString (Traversal' t v) where
fromString k = key' (fromString k) . non (toJSON def) . _JSON
在 State monad 中实现这样的目标:
"some-key" .= (3 :: Int)
普遍量化类型实例的问题。谢谢!