Skip to content

Instantly share code, notes, and snippets.

@kgadek
Created July 30, 2014 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgadek/ae8b4079e0d4e181d006 to your computer and use it in GitHub Desktop.
Save kgadek/ae8b4079e0d4e181d006 to your computer and use it in GitHub Desktop.
question on lenses/prisms
{-# 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