मुझे नहीं लगता कि यह स्वचालित रूप से किया जा सकता है, लेकिन हाथ से कुछ लेंस लिख इस विशेष मामले में है कि मुश्किल नहीं है:,
{-# LANGUAGE GADTs #-}
import Control.Lens
data D a b where
D :: (Ord a, Ord b) => !a -> !b -> D a b
field1 :: Lens' (D a b) a
field1 f (D x y) = fmap (\x' -> D x' y) (f x)
field2 :: Lens' (D a b) b
field2 f (D x y) = fmap (\y' -> D x y') (f y)
{- If you want type-changing lenses, you can also use these signatures.
- Note that then the target type Ord constraint has to escape.
field1 :: (Ord a2) => Lens (D a1 b) (D a2 b) a1 a2
field2 :: (Ord b2) => Lens (D a b1) (D a b2) b1 b2
-}
वहाँ कुछ हद तक एक प्रासंगिक GitHub issue प्रतीत हो रहा है, जिसमें Kmett दावा है कि वे अस्तित्व में प्रमाणित क्षेत्रों के लिए लेंस नहीं बना सकते हैं।
स्रोत
2015-01-26 06:53:56
मुझे पूछना है: क्या उन्हें हाथ से लिखना संभव है? – dfeuer