Skip to content

Instantly share code, notes, and snippets.

@mxswd
Last active January 2, 2016 22:09
Show Gist options
  • Save mxswd/8367868 to your computer and use it in GitHub Desktop.
Save mxswd/8367868 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TemplateHaskell, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}
module SingLens where
import Control.Lens
import SuperLens ((???), makeLensesPlus)
data Foo = Foo { _bar :: String, _baz :: Int } deriving Show
makeLensesPlus ''Foo
-- | f
-- >>> f
-- Foo {_bar = "four", _baz = 3}
f :: Foo
f = Foo "four" 3
-- | g
-- >>> g
-- "four"
g :: String
g = view (???) f
-- | h
-- >>> h
-- 3
h :: Int
h = view (???) f
-- | i
-- >>> i
-- Foo {_bar = "bar", _baz = 3}
i :: Foo
i = set (???) "bar" f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment