Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created May 29, 2020 07:55
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 tonymorris/d8e660423ec3ad90a5cd2ee6502ba74b to your computer and use it in GitHub Desktop.
Save tonymorris/d8e660423ec3ad90a5cd2ee6502ba74b to your computer and use it in GitHub Desktop.
{-# 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
@pedrofurla
Copy link

boolyFunction' = bool "abc" . (++ "def") . show <*> isn't _DataTypeWithMillionsOfConstructors0 is neat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment