Last active
October 25, 2016 10:09
-
-
Save danidiaz/84657b042eefb812dddd65f46f055731 to your computer and use it in GitHub Desktop.
Generics-SOP + record pattern synonyms https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#record-pattern-synonyms http://stackoverflow.com/a/40227704/1364288
This file contains hidden or 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
{-# language DeriveGeneric #-} | |
{-# language TypeFamilies #-} | |
{-# language TypeOperators #-} | |
{-# language PatternSynonyms #-} | |
import Data.Text | |
import qualified GHC.Generics as GHC | |
import Generics.SOP | |
import Text.Read | |
data Foo = Foo { x :: Int, y :: Text } deriving (Show, GHC.Generic) | |
instance Generic Foo | |
pattern Foo' :: t Int -> t Text -> SOP t (Code Foo) | |
pattern Foo' {x', y'} = SOP (Z (x' :* y' :* Nil)) | |
readFooMaybe :: SOP (IO :.: Maybe) (Code Foo) | |
readFooMaybe = Foo' | |
{ | |
x' = Comp (fmap readMaybe getLine) | |
, y' = Comp (fmap readMaybe getLine) | |
} | |
main :: IO () | |
main = do | |
r <- hsequence' readFooMaybe | |
print r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment