summaryrefslogtreecommitdiff
path: root/Example.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-02 06:49:58 +0300
committerdefanor <defanor@uberspace.net>2017-12-02 06:49:58 +0300
commitc84dbc16bbf683661e8323c68326ee04c8daf2fc (patch)
tree04ab0517a2dbe465ad1f0a158eae9b707fd73655 /Example.hs
parent4beea4536a36322e15665de74c96926f0cf5fe7b (diff)
Use GHC.Generics instead of TH
It's considerably cleaner and simpler with GHC.Generics. Megaparsec is also used now.
Diffstat (limited to 'Example.hs')
-rw-r--r--Example.hs34
1 files changed, 18 insertions, 16 deletions
diff --git a/Example.hs b/Example.hs
index 20cae00..725f8cc 100644
--- a/Example.hs
+++ b/Example.hs
@@ -1,27 +1,29 @@
-{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE DeriveGeneric #-}
module Main where
+import GHC.Generics
+import Text.Megaparsec
import Coalpit
-import Language.Haskell.TH
-import Data.List
-data Y = Foo Bool Int
- | Bar Int
- | Baz
- deriving (Show)
+data RecTest = RecTest { a :: Int, b :: Double }
+ deriving (Generic, Show)
-data X = X String (Maybe Int) (Maybe [Int]) Y Y String
- deriving (Show)
+instance ArgParser RecTest
+instance ToArgs RecTest
-$(deriveArgs ''Y)
-$(deriveArgs ''X)
+data Foo = Bar Int
+ | Baz Int
+ | Qux RecTest
+ deriving (Generic, Show)
+
+instance ToArgs Foo
+instance ArgParser Foo
main :: IO ()
main = do
- let val = X "test" Nothing (Just [1,2,3]) (Foo True 1) Baz "end"
- args = toArgs val
+ let val = Qux (RecTest 1 2.3)
+ a = args val
print val
- putStrLn $ intercalate " " args
- print (fromArgs args :: (X, [String]))
- print (fromArgs (args ++ ["additional", "args"]) :: (X, [String]))
+ putStrLn a
+ print $ parse (argParser :: Parser Foo) "test" a