Last active
January 10, 2018 15:06
-
-
Save iokasimov/ed5f16b1c9fa55af34a7aeb941fdc23b to your computer and use it in GitHub Desktop.
Lenses are exactly the Coalgebras for the Store Comonad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Function | |
import Control.Comonad.Store | |
type Lens a b = a -> Store b a | |
(^.) :: Lens a b -> a -> b | |
(^.) lens = pos . lens | |
(.~) :: Lens a b -> b -> a -> a | |
lens .~ new = peek new . lens | |
type Name = String | |
type Address = String | |
type Job = Maybe String | |
data Person = Person Name Address Job deriving Show | |
name :: Lens Person Name | |
name (Person n a j) = store (\new -> Person new a j) n | |
me :: Person | |
me = Person "Murat Kasimov" "Serokell" Nothing | |
main = do | |
print "typechecked" | |
print $ name ^. me | |
print $ me & name .~ "Clint Eastwood" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment