Last active
December 24, 2015 03:08
-
-
Save danidiaz/6734938 to your computer and use it in GitHub Desktop.
Prism adventures
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
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import Control.Lens | |
import System.IO | |
-- Note that data constructors can't begin with underscore _ | |
data Foo = A Int Int | B Char Char | |
makePrisms ''Foo | |
main :: IO () | |
main = do | |
putStrLn . show $ firstOf _A $ B 'a' 'c' | |
putStrLn . show $ firstOf _A $ A 3 5 | |
putStrLn . show $ preview _A $ B 'a' 'c' | |
putStrLn . show $ preview _A $ A 3 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment