Created
May 29, 2020 07:55
-
-
Save tonymorris/d8e660423ec3ad90a5cd2ee6502ba74b to your computer and use it in GitHub Desktop.
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
{-# OPTIONS_GHC -Wall #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
import Control.Lens | |
import Data.Bool | |
data DataTypeWithMillionsOfConstructors = | |
DataTypeWithMillionsOfConstructors0 | |
| DataTypeWithMillionsOfConstructors1 | |
| DataTypeWithMillionsOfConstructors2 | |
| DataTypeWithMillionsOfConstructors3 | |
| DataTypeWithMillionsOfConstructors4 | |
| DataTypeWithMillionsOfConstructors5 | |
| DataTypeWithMillionsOfConstructors6 | |
| DataTypeWithMillionsOfConstructors7 | |
| DataTypeWithMillionsOfConstructors8 | |
| DataTypeWithMillionsOfConstructors9 | |
deriving (Eq, Ord, Show) | |
boolyFunction :: DataTypeWithMillionsOfConstructors -> String | |
boolyFunction DataTypeWithMillionsOfConstructors0 = "abc" | |
-- it would really suck to have to write out all the constructors | |
-- to achieve non-overlapping patterns | |
-- At some point we must trade off -- with this trade, I agree. | |
boolyFunction msg = show msg ++ "def" | |
---- | |
-- but really, you want optics anyway | |
-- make all the prisms | |
makeClassyPrisms ''DataTypeWithMillionsOfConstructors | |
boolyFunction' :: DataTypeWithMillionsOfConstructors -> String | |
-- boolyFunction' = \x -> bool "abc" (show x ++ "def") (isn't _DataTypeWithMillionsOfConstructors0 x) | |
boolyFunction' = bool "abc" . (++ "def") . show <*> isn't _DataTypeWithMillionsOfConstructors0 | |
-- demonstrate the type of _DataTypeWithMillionsOfConstructors0 | |
typeof :: AsDataTypeWithMillionsOfConstructors x => Prism' x () | |
typeof = _DataTypeWithMillionsOfConstructors0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
boolyFunction' = bool "abc" . (++ "def") . show <*> isn't _DataTypeWithMillionsOfConstructors0
is neat