Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jchia/43c3adee41d522d03c546142bb79b651 to your computer and use it in GitHub Desktop.
Save jchia/43c3adee41d522d03c546142bb79b651 to your computer and use it in GitHub Desktop.
data Config = Config { x :: Int, y :: Int }
defaultConfig :: Config
data Options' a = OptionsA { queue :: Text }
| OptionsB { config :: a, queue :: Text, a :: Text, b :: Maybe Int }
| OptionsC { config :: a, queue :: Text, c :: Int, d :: Word8 }
| OptionsD { config :: a, queue :: Text, c :: [Word8], d :: Bool }
using Options1 = Options' (Maybe Text)
using Options2 = Options' Config
readConfig :: MonadIO m => Maybe Text -> m Config
readConfig Nothing = pure defaultConfig
readConfig (Just fp) = ... -- reads and parses Config from a file with path fp.
-- What's a non-boilerplatey way of defining convertOptions1ToOptions2, avoiding
-- exhaustively defining for individual data constructors?
convertOptions1ToOptions2 :: MonadIO m Options1 -> m Options2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment