Haskell – Haskell

Haskell

Haskell – 本题是一个利用Haskell进行练习的代做, 对Haskell的流程进行训练解析, 包括了Haskell等方面

haskell代写 代写haskell

Theobjectiveofthisassignmentistoallowyoutopracticewithbothalgebraicdatatypesandtail-calloptimizationby exploringthecreationofthreerecursive"longdivision"calculatingfunctions.Longdivisionisactuallyrepresentative ofsuccessivesubtractionoperationsofthedivisor(i.e.,denominator)fromthedividend(i.e.,numerator).

Forinstance, 22 7 (forwhichthequotientis 3 andtheremainderis1)iscomputedbysuccessivesubtractionof 7 from 22 untilthedifferencewouldbenegative; 22 7 =15; 15 7 =8; 8 7 =1,andsincethreesubtraction operationswereperformedandthefinaldifferencewasone,thequotientis 3 andtheremainderis1.

Youmustdesignandimplementarecursivelongdivisionfunctionthattakestwointegerarguments(n.b.,thedividend andthedivisor,inthatorder)andproducesa2-tupleofintegers(i.e.,thequotientandtheremainder).

Asthefunctiondescribedaboveisthefirstofthethreelongdivisionfunctionsyouwillwrite,handlethecaseof divisionbyzerousingHaskell’s"error"function(whichinturnwillrequirethatyouconsultthe Haskell documentation).

Youmustdesignandimplementasecondrecursivelongdivisionfunctionthattakestwointegerargumentsandis capableofreturningboththequotientandtheremainderwithasinglecall,butthissecondversionofthefunction requiresthatyouuseaMaybetypetoeliminatetheneedforthe"error"thatoccursduringdivisionbyzero.Toclarify, thisapproachwillassumethatdivisionbyzeroresultsinnothing…

Youmaywishtowriteyourownselectorfunctionstosupportthesecondfunctiondescribedabove.

Youmustdesignandimplementathirdrecursivelongdivisionfunctionthatusestail-calloptimization;thiswill obviouslyrequirethatyouwriteahelperfunctionaswell,butyoucanassumethatthisthirdfunctionwillneverbe calledwithadivisorofzero(soyoucanomittheuseoftheerrorfunctionandtheuseofMaybe).

Youmustnotuseanybuilt-infunctionsotherthan"error"and"fst"/"snd"(shouldyouwishtousetheselector function).