Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Created October 20, 2022 17:14
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 Lysxia/0951fc852da2bb3274433f241a013307 to your computer and use it in GitHub Desktop.
Save Lysxia/0951fc852da2bb3274433f241a013307 to your computer and use it in GitHub Desktop.
Deriving Read and Show for records as if they weren't records
{-# LANGUAGE DeriveGeneric, DerivingVia #-}
import GHC.Generics (Generic)
import Generic.Data
import Generic.Data.Microsurgery
data R = R {a :: Int, b :: Int}
deriving Generic
deriving (Read, Show) via Surgery Derecordify R
main :: IO ()
main = do
print (read "R 0 1" :: R)
-- Output: R 0 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment