No title

Anonymous Coward 2018-03-08 04:35:56.901031 UTC

1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE TypeApplications #-}
4
5import Control.Lens
6import Control.Lens.Extras (is)
7import Data.Generics.Sum.Constructors
8import GHC.Generics
9
10data Wiggle = Woo Int Char | Wibble Int deriving (Generic, Show)
11
12main = do
13 print $ is (_Ctor @"Woo") (Woo 0 '0')
14 print $ Woo 1 '1' ^? _Ctor @"Woo"
15 print $ over (_Ctor @"Left") succ (Left 3 :: Either Int Bool)
16 print $ either (const "") (\(x, y) -> show x ++ show y)
17 (matching (_Ctor @"Woo") (Wibble 0))