Created
July 30, 2014 11:26
-
-
Save kgadek/ae8b4079e0d4e181d006 to your computer and use it in GitHub Desktop.
question on lenses/prisms
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 #-} | |
import Control.Lens | |
import Test.Hspec | |
import Control.Monad | |
data Gene = X {_ident::Int, _xx::String} | Y {_ident::Int, _yy::Char} | |
makeLenses ''Gene | |
makePrisms ''Gene | |
gen1 = X 123 "xx" | |
gen2 = Y 456 'y' | |
main :: IO () | |
main = hspec spec | |
spec :: Spec | |
spec = do | |
describe "testtest" $ do | |
it "is prismable 4" $ (gen1 ^. xx) `shouldBe` "xx" | |
it "is prismable 5" $ (gen1 ^? xx) `shouldBe` (Just "xx") | |
it "is prismable 6" $ (gen2 ^. xx) `shouldBe` mzero -- how to make this *not* typecheck… | |
it "is prismable 7" $ (gen2 ^? xx) `shouldBe` Nothing -- …but this be okay? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment