generics-sop . generics-sop Generics .
ReadP, , Applicative . :
{-
{-
{-
{-
{-
{-
import Text.ParserCombinators.ReadP (ReadP,readP_to_S)
import Text.ParserCombinators.ReadPrec (readPrec_to_P)
import Text.Read (readPrec)
import Data.Proxy
import qualified GHC.Generics as GHC
import Generics.SOP
, Applicative . Int Bool:
class HasSimpleParser c where
getSimpleParser :: ReadP c
instance HasSimpleParser Int where
getSimpleParser = readPrec_to_P readPrec 0
instance HasSimpleParser Bool where
getSimpleParser = readPrec_to_P readPrec 0
, HasSimpleParser:
recParser :: (Generic r, Code r ~ '[xs], All HasSimpleParser xs) => ReadP r
recParser = to . SOP . Z <$> hsequence (hcpure (Proxy @HasSimpleParser) getSimpleParser)
Code r ~ '[xs], All HasSimpleParser xs , " , xs, HasSimpleParser ".
hcpure n- (NP), r. (NP , ReadP).
hsequence, n- n- .
, n- r, to, Z SOP n- , to.
, Generics.SOP.Generic:
data Foo = Foo { x :: Int, y :: Bool } deriving (Show, GHC.Generic)
instance Generic Foo -- Generic from generics-sop
Foo recParser:
main :: IO ()
main = do
print $ readP_to_S (recParser @Foo) "55False"
[(Foo {x = 55, y = False},"")]