6 Pieter Koopman, pieter@cs.ru.nl
7 Advanced Programming. Skeleton for assignment 4 in 2018
8 - use this a project with environment iTasks
9 - executable must be in Examples/iTasks or a subdirectory
10 You can also use the -sdk commandline flag to set the path
20 :: BaMa = Bachelor | Master
57 student = students !! 0
59 derive class iTask Student, BaMa
60 derive gToString Student, BaMa
62 generic gToString a :: a -> String
63 gToString{|Int|} i = toString i
64 gToString{|String|} s = s
65 gToString{|UNIT|} _ = ""
66 gToString{|RECORD|} fx (RECORD x) = "{" + fx x + "}"
67 gToString{|FIELD of {gfd_name}|} fx (FIELD x) = gfd_name + "=" + fx x + " "
68 gToString{|PAIR|} fx fy (PAIR x y) = fx x + fy y
69 gToString{|EITHER|} fx fy (LEFT x) = fx x
70 gToString{|EITHER|} fx fy (RIGHT y) = fy y
71 gToString{|CONS of {gcd_name}|} fx (CONS x) = gcd_name + fx x
72 gToString{|OBJECT|} fx (OBJECT x) = fx x
74 instance + String where + s t = s +++ t
76 Start w = doTasks (changeName student) w
78 enterStudent :: Task Student
79 enterStudent = enterInformation "Enter a student" []
81 enterStudentList :: Task [Student]
82 enterStudentList = enterInformation "Enter a student" []
84 updateStudent :: (Student -> Task Student)
85 updateStudent = updateInformation "Update a student" []
87 selectStudent :: ([Student] -> Task Student)
88 selectStudent = enterChoice "Pick a student" []
90 selectStudentOnlyName :: ([Student] -> Task Student)
91 selectStudentOnlyName = enterChoice "Pick a student" [ChooseFromDropdown \s->s.Student.name]
93 selectStudentFormat :: ([Student] -> Task Student)
94 selectStudentFormat = enterChoice "Pick a student" [ChooseFromDropdown gToString{|*|}]
96 selectPartner :: ([Student] -> Task [Student])
97 selectPartner = enterMultipleChoice "Pick a partner" [ChooseFromDropdown \s->s.Student.name + "(" + gToString{|*|} s.Student.bama + ")"]
99 changeName :: Student -> Task Student
101 = viewInformation "Student to change" [] s
102 ||- updateInformation "New name" [UpdateAs (\s->s.Student.name) (\s n->{Student | s & name=n})] s
104 changeNameEdcomb :: Student -> Task Student
106 = updateInformation "New name" [UpdateUsing id (\_ v->v) studed] s
108 studed :: Editor Student
109 studed = bijectEditorValue
110 (\s->(s.Student.name, s.snum, s.bama, s.year))
111 (\(n,s,b,y)->{name=n,snum=s,bama=b,year=y})
114 (withChangedEditMode toView gEditor{|*|})
115 (withChangedEditMode toView gEditor{|*|})
116 (withChangedEditMode toView gEditor{|*|})
118 toView (Update a) = View a