moduleEvotingimportData.VectimportData.List%defaulttotalName:TypeName=StringSurname:TypeSurname=StringdataCandidate=PersonNameSurnamedataVote=Blank|ForCandidatedataValidity=ValidVote|InvalidEqCandidatewhere(Personname1surname1)==(Personname2surname2)=name1==name2&&surname1==surname2(Personname1surname1)/=(Personname2surname2)=name1/=name2||surname1/=surname2validity:ListCandidate->Vote->Validityvalidity(Nil)__________=Invalidvalidity_________(Blank)=ValidBlankvalidity(x::xs)(Forvote)=ifx==votethenValid(Forvote)elsevalidityxs(Forvote)invalidate:VectnVote->VectnValidityinvalidate(Nil)=Nilinvalidate(_::xs)=Invalid::invalidatexselection:ListCandidate->VectnVote->VectnValidityelection__________(Nil)=NilelectionNil(votes)=invalidatevoteselectioncandidates(vote::votes)=validitycandidatesvote::electioncandidatesvotescandidates:ListCandidatecandidates=Person"John""Doe"::Person"Jane""Doe"::[]{- Version 1: Replicate real life behaviour -}votes:Vect3Vote{- We know the number of citizens -}votes=For(Person"Jane""Doe")::For(Person"John""Hoe")::{- Invalid candidate -}Blank::[]
Idris Code output:
Welcome to the Idris REPL!
Idris 1.0
Type checking ./evoting.idr
λΠ> election candidates votes
[Valid (For (Person "Jane" "Doe")), Invalid, Valid Blank] : Vect 3 Validity
λΠ>