[Haskell-beginners] Type constructors sharing a common field

John M. Dlugosz ngnr63q02 at sneakemail.com
Wed Apr 30 13:38:06 UTC 2014


On 4/29/2014 10:55 AM, Benjamin Edwards wrote:
> |module  Mainwhere
>
> import  Control.Applicative
> import  Control.Lens
>
> main  ::IO  ()
> main  =let  p =Child  10
>          in  print $ p ^. age
>
> data  Person  =Child  Int  |Adult  Int
>
> age  ::Lens'  Person  Int
> age  k (Child  x) =Child  <$> k x
> age  k (Adult  x) =Adult  <$> k x
> |


Hmm, what does the <$> mean here?  I know it for functor application, but I don't 
understand how that works in this example.




More information about the Beginners mailing list