AutoForms-0.4.0: src/Examples/Misc/Person.hs
{-# LANGUAGE FlexibleContexts, FlexibleInstances
, MultiParamTypeClasses, TemplateHaskell, UndecidableInstances #-}
{-
This class contains a person data type and one instantiation
(somePerson) of the datatype. The data type have been made ready for
use with the SYB3 ("Scrap Your Boilerplate" 3) library. However, it is
still not ready to be used with the AutoForm library, as all data
types needs to be instances of the GAutoForm class. These instance
declarations are in the PersonTest.hs file.
It is good to keep the data types, needed to be used with the SYB3
library in a seperate file, as it requires the use of
-fallow-undecidable-instances.
-}
module Person where
import Graphics.UI.AF.General.MySYB
import Time (Month (January, February, March, April, May, June
, July, August, September, October, November, December)
)
somePerson = (Person (Just $ Name "Walter" "Hansen")
(Address "Bernhoffstrasse 27" "Berlin" 12345)
(Birthday (Date 1970 March 3)) (Salary (Sal 47892.23)) (Red)
(SpecialYears [[1980,1982,1999]])
)
data Person = Person (Maybe Name) Address Birthday Salary FavoriteColor SpecialYears deriving (Show, Eq, Read)
data Name = Name { first_Name :: String, sir_name :: String } deriving (Show, Eq, Read)
data Address = Address { road :: String, city :: String, zipCode :: Int } deriving (Show, Eq, Read)
data Birthday = Birthday Date deriving (Show, Eq, Read)
data Salary = Salary Sal deriving (Show, Eq, Read)
data Sal = Sal Double deriving (Show, Eq, Read)
data FavoriteColor = Black [Int] | Blue [(Int, String)] | White | Red deriving (Show, Eq, Read)
data SpecialYears = SpecialYears [[Int]] deriving (Show, Eq, Read)
data Date = Date { year :: Int, month :: Month, day :: Int } deriving (Show, Eq, Read)
$(derive [''Name,''Address,''Month,''Birthday,''Date,''Sal,''Salary,''FavoriteColor,''SpecialYears,''Person])