Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
majorityJudgment
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
delanoe
majorityJudgment
Commits
4178a1b9
Commit
4178a1b9
authored
Dec 19, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more realistic example.
parent
4bc88295
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
Lib.hs
src/Lib.hs
+11
-11
No files found.
src/Lib.hs
View file @
4178a1b9
...
@@ -69,12 +69,21 @@ ballots3 :: MajorityJudgment
...
@@ -69,12 +69,21 @@ ballots3 :: MajorityJudgment
ballots3
=
[
Ballot
"Dictatorship"
(
ratedAs
[(
1
,
Excellent
)])]
ballots3
=
[
Ballot
"Dictatorship"
(
ratedAs
[(
1
,
Excellent
)])]
ballots4
::
MajorityJudgment
ballots4
::
MajorityJudgment
ballots4
=
[
Ballot
"
Dictatorship"
(
ratedAs
[(
10
0
,
Excellent
)])
ballots4
=
[
Ballot
"
Fascism"
(
ratedAs
[(
9
0
,
Excellent
)])
,
Ballot
"Democracy"
(
ratedAs
[(
1
,
Excellent
)])
,
Ballot
"Democracy"
(
ratedAs
[(
10
,
Excellent
),
(
90
,
Poor
)])
]
]
------------------------------------------------------------------------
------------------------------------------------------------------------
-- | Select the Winner
-- TODO: sortBy and intersect according to Result
-- sort then take While equality
winnerIs
::
MajorityJudgment
->
Either
Text
(
Maybe
Ballot
)
winnerIs
mj
=
case
isFair
mj
of
False
->
Left
"Unfair Election"
True
->
Right
$
(
headMay
.
reverse
.
sort
)
mj
-- | Asserts is the Election with Majority Judgment is Fair
-- | Asserts is the Election with Majority Judgment is Fair
-- e.g. methodology of vote is respected to collect the ballots
-- e.g. methodology of vote is respected to collect the ballots
-- Number of vote per Ballot must be equal
-- Number of vote per Ballot must be equal
...
@@ -87,15 +96,6 @@ isFair mj = length vs > 2 && all (== head vs) vs
...
@@ -87,15 +96,6 @@ isFair mj = length vs > 2 && all (== head vs) vs
data
Unfair
=
NoChoice
|
NoRepresentativity
data
Unfair
=
NoChoice
|
NoRepresentativity
-- undefined -- all . map (length . votes)
-- | Select the Winner
-- TODO: sortBy and intersect according to Result
-- sort then take While equality
winnerIs
::
MajorityJudgment
->
Either
Text
(
Maybe
Ballot
)
winnerIs
mj
=
case
isFair
mj
of
False
->
Left
"Unfair Election"
True
->
Right
$
(
headMay
.
reverse
.
sort
)
mj
instance
Eq
Ballot
where
instance
Eq
Ballot
where
(
==
)
(
Ballot
_
v1
)
(
Ballot
_
v2
)
=
(
==
)
(
score
v1
)
(
score
v2
)
(
==
)
(
Ballot
_
v1
)
(
Ballot
_
v2
)
=
(
==
)
(
score
v1
)
(
score
v2
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment