-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstract.hs
More file actions
executable file
·28 lines (23 loc) · 944 Bytes
/
Copy pathAbstract.hs
File metadata and controls
executable file
·28 lines (23 loc) · 944 Bytes
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
data OS = Linux | MacOS | Windows
newtype Button = Button OS
click :: Button -> String
click (Button Linux) = "Created Linux Button"
click (Button MacOS) = "Created Mac Button"
click (Button Windows) = "Created Windows Button"
newtype Checkbox = Checkbox OS
check :: Checkbox -> String
check (Checkbox Linux) = "Checked Linux"
check (Checkbox MacOS) = "Checked MacOS"
check (Checkbox Windows) = "Checked Windows"
-- Example with Employee
data Spec = Programmer | Engineer | Manager deriving (Show)
data Employee = Employee {fName::String, lName::String, spec::Spec} deriving (Show)
calcSalary :: Employee -> Double
calcSalary e = case spec e of
Programmer -> 1550
Engineer -> 1600
Manager -> 1400
getInfo :: Employee -> String
getInfo (Employee f l Programmer) = unwords [f, l, "is a Programmer"]
getInfo (Employee f l Engineer) = unwords [f, l, "is an Engineer"]
getInfo (Employee f l Manager) = unwords [f, l, "is a Manager"]