Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active October 25, 2016 10:09
Show Gist options
  • Save danidiaz/84657b042eefb812dddd65f46f055731 to your computer and use it in GitHub Desktop.
Save danidiaz/84657b042eefb812dddd65f46f055731 to your computer and use it in GitHub Desktop.
{-# 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