Created
April 14, 2015 07:27
-
-
Save tokiwoousaka/c88a4bfd32d3d75d202f to your computer and use it in GitHub Desktop.
makePrismsの再実装はつらみしか無さそうなので、実際のLensで動きだけ確認
This file contains hidden or 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 #-} | |
module Main where | |
import Control.Lens | |
data Foo a b = Hoge a | Piyo b | Fuga String | |
deriving (Show, Read, Eq, Ord) | |
makePrisms ''Foo | |
----- | |
foo1 :: Foo Int Bool | |
foo1 = Hoge 10 | |
foo2 :: Foo Int Bool | |
foo2 = Piyo True | |
foo3 :: Foo Int Bool | |
foo3 = Fuga "Hello" | |
foo4 :: Foo (Int, Bool, String) Bool | |
foo4 = Hoge (10, False, "Hoge") | |
main :: IO () | |
main = do | |
let foos = (foo1, foo2, foo3, foo4) | |
print foos | |
putStrLn "----------" | |
print $ foos^?_3._Fuga | |
print $ foos^?_4._Piyo | |
print $ foos^?_4._Hoge._1 | |
putStrLn "----------" | |
print $ foos&_2._Piyo.~False | |
print $ foos&_4._Hoge._3.~"Hello! Prism" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment