packages feed

HaXml-1.13.2: examples/DTypes.hs

{-% DrIFT (Automatic class derivations for Haskell) v1.0 %-}
module DTypes where

import Text.XML.HaXml.Haskell2Xml hiding (Name)

-- data types for a simple test program

data Person = Person Name Email [Rating] Version {-! derive :Haskell2Xml !-}

newtype Name = Name String {-! derive :Haskell2Xml !-}
newtype Email = Email String {-! derive :Haskell2Xml !-}
newtype Version = Version Int {-! derive :Haskell2Xml !-}

data Rating = Rating SubjectID Interest Skill {-! derive :Haskell2Xml !-}

newtype SubjectID = SubjectID Int {-! derive :Haskell2Xml !-}
newtype Interest = Interest Score {-! derive :Haskell2Xml !-}
newtype Skill = Skill Score {-! derive :Haskell2Xml !-}

data Score = ScoreNone | ScoreLow | ScoreMedium | ScoreHigh {-! derive :Haskell2Xml !-}

{-* Generated by DrIFT-v1.0 : Look, but Don't Touch. *-}
instance Haskell2Xml Person where
    toHType v =
	Defined "Person" []
		[Constr "Person" []
			[toHType aa,toHType ab,toHType ac,toHType ad]]
      where
	(Person aa ab ac ad) = v
    fromContents (CElem (Elem constr [] cs):etc)
	| "Person" `isPrefixOf` constr =
	    (\(aa,cs00)-> (\(ab,cs01)-> (\(ac,cs02)-> (\(ad,
							 _)-> (Person aa ab ac ad, etc))
						      (fromContents cs02))
					(fromContents cs01))
			  (fromContents cs00))
	    (fromContents cs)
    toContents v@(Person aa ab ac ad) =
	[mkElemC (showConstr 0 (toHType v)) (concat [toContents aa,toContents ab
						     ,toContents ac,
						     toContents ad])]

instance Haskell2Xml Name where
    toHType v =
	Defined "Name" [] [Constr "Name" [] [toHType aa]]
      where
	(Name aa) = v
    fromContents (CElem (Elem constr [] cs):etc)
	| "Name" `isPrefixOf` constr =
	    (\(aa,_)-> (Name aa, etc)) (fromContents cs)
    toContents v@(Name aa) =
	[mkElemC (showConstr 0 (toHType v)) (toContents aa)]

instance Haskell2Xml Email where
    toHType v =
	Defined "Email" [] [Constr "Email" [] [toHType aa]]
      where
	(Email aa) = v
    fromContents (CElem (Elem constr [] cs):etc)
	| "Email" `isPrefixOf` constr =
	    (\(aa,_)-> (Email aa, etc)) (fromContents cs)
    toContents v@(Email aa) =
	[mkElemC (showConstr 0 (toHType v)) (toContents aa)]

instance Haskell2Xml Version where
    toHType v =
	Defined "Version" [] [Constr "Version" [] [toHType aa]]
      where
	(Version aa) = v
    fromContents (CElem (Elem constr [] cs):etc)
	| "Version" `isPrefixOf` constr =
	    (\(aa,_)-> (Version aa, etc)) (fromContents cs)
    toContents v@(Version aa) =
	[mkElemC (showConstr 0 (toHType v)) (toContents aa)]

instance Haskell2Xml Rating where
    toHType v =
	Defined "Rating" []
		[Constr "Rating" [] [toHType aa,toHType ab,toHType ac]]
      where
	(Rating aa ab ac) = v
    fromContents (CElem (Elem constr [] cs):etc)
	| "Rating" `isPrefixOf` constr =
	    (\(aa,cs00)-> (\(ab,cs01)-> (\(ac,_)-> (Rating aa ab ac, etc))
					(fromContents cs01))
			  (fromContents cs00))
	    (fromContents cs)
    toContents v@(Rating aa ab ac) =
	[mkElemC (showConstr 0 (toHType v)) (concat [toContents aa,toContents ab
						     ,toContents ac])]

instance Haskell2Xml SubjectID where
    toHType v =
	Defined "SubjectID" [] [Constr "SubjectID" [] [toHType aa]]
      where
	(SubjectID aa) = v
    fromContents (CElem (Elem constr [] cs):etc)
	| "SubjectID" `isPrefixOf` constr =
	    (\(aa,_)-> (SubjectID aa, etc)) (fromContents cs)
    toContents v@(SubjectID aa) =
	[mkElemC (showConstr 0 (toHType v)) (toContents aa)]

instance Haskell2Xml Interest where
    toHType v =
	Defined "Interest" [] [Constr "Interest" [] [toHType aa]]
      where
	(Interest aa) = v
    fromContents (CElem (Elem constr [] cs):etc)
	| "Interest" `isPrefixOf` constr =
	    (\(aa,_)-> (Interest aa, etc)) (fromContents cs)
    toContents v@(Interest aa) =
	[mkElemC (showConstr 0 (toHType v)) (toContents aa)]

instance Haskell2Xml Skill where
    toHType v =
	Defined "Skill" [] [Constr "Skill" [] [toHType aa]]
      where
	(Skill aa) = v
    fromContents (CElem (Elem constr [] cs):etc)
	| "Skill" `isPrefixOf` constr =
	    (\(aa,_)-> (Skill aa, etc)) (fromContents cs)
    toContents v@(Skill aa) =
	[mkElemC (showConstr 0 (toHType v)) (toContents aa)]

instance Haskell2Xml Score where
    toHType v =
	Defined "Score" []
		[Constr "ScoreNone" [] [],Constr "ScoreLow" [] [],
		 Constr "ScoreMedium" [] [],Constr "ScoreHigh" [] []]
    fromContents (CElem (Elem constr [] cs):etc)
	| "ScoreNone" `isPrefixOf` constr =
	    (ScoreNone,etc)
	| "ScoreLow" `isPrefixOf` constr =
	    (ScoreLow,etc)
	| "ScoreMedium" `isPrefixOf` constr =
	    (ScoreMedium,etc)
	| "ScoreHigh" `isPrefixOf` constr =
	    (ScoreHigh,etc)
    toContents v@ScoreNone =
	[mkElemC (showConstr 0 (toHType v)) []]
    toContents v@ScoreLow =
	[mkElemC (showConstr 1 (toHType v)) []]
    toContents v@ScoreMedium =
	[mkElemC (showConstr 2 (toHType v)) []]
    toContents v@ScoreHigh =
	[mkElemC (showConstr 3 (toHType v)) []]

--  Imported from other files :-