I'm not able to figure out how to compose nicely access to a Data.Map with a lens accessing a record. Say that I have:
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Control.Lens.TH
import Data.Map
data Person =
Person
{ _age :: Int
, _name :: String
}
deriving (Show)
makeLenses ''Person
database = fromList [(1, Person 35 "John")]
What would be the one liner that allows getting John's age? Because
johsnAge = database ^. at 1 . _Just . age
Is giving me error:
• No instance for (Monoid Int) arising from a use of ‘_Just’
• In the first argument of ‘(.)’, namely ‘_Just’
In the second argument of ‘(.)’, namely ‘_Just . age’
In the second argument of ‘(^.)’, namely ‘at 1 . _Just . age’
|
18 | johsnAge = database ^. at 1 . _Just . age
|