-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatatypes.hs
66 lines (52 loc) · 1.58 KB
/
datatypes.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--import Data.Time
--main = do
-- c <- getCurrentTime
-- let (y,m,d) = toGregorian $ utctDay c in
-- print y
-- DATE
data Date = Date Int Int Int
deriving Eq -- M/D/Y
month (Date x _ _) = x
day (Date _ x _) = x
year (Date _ _ x) = x
monthName m
| m == 1 = "January"
| m == 2 = "February"
| m == 3 = "March"
| m == 4 = "April"
| m == 5 = "May"
| m == 6 = "June"
| m == 7 = "July"
| m == 8 = "August"
| m == 9 = "September"
| m == 10 = "November"
| m == 11 = "October"
| m == 12 = "December"
ordinalSuffix m
| mod m 10 == 1 = "st"
| mod m 10 == 2 = "nd"
| mod m 10 == 3 = "rd"
| otherwise = "th"
ordinal x = show x ++ ordinalSuffix x
fullMonth d = monthName (month d)
fullDate d = ordinal (day d)
-- note the scoping of ++
instance Show Date where
show d = fullMonth d ++ " " ++ fullDate d ++ ", " ++ show (year d)
oneOr x = min 1 x
formattedDateNumber d = day d + oneOr (month d) * 100 + oneOr (year d) * 10000
--compareD a b = compare (formattedDateNumber a) (formattedDateNumber b)
instance Ord Date where
compare a b = compare (formattedDateNumber a) (formattedDateNumber b)
--show :: (Integral a) => a -> String
---- FAMILY TREE
type FirstName = String
type LastName = String
type Parents = [Person]
type Children = [Person]
type Birthdate = Date
data Person = Person FirstName LastName Birthdate Parents Children
firstName (Person first _ _ _ _) = first
lastName (Person _ last _ _ _) = last
fullname p = firstName p ++ " " ++ lastName p
birthdate (Person _ _ d _ _) = d