Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active December 24, 2015 03:08
Show Gist options
  • Save danidiaz/6734938 to your computer and use it in GitHub Desktop.
Save danidiaz/6734938 to your computer and use it in GitHub Desktop.
Prism adventures
{-# 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