



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




For Grading
local Answer G = fun {$ X} X (^) * X end in Answer = {G 3} end
{Test {ScalarMultiply nil 3} ’=’ nil} {Test {ScalarMultiply 7|nil 3} ’=’ 21|nil} {Test {ScalarMultiply [1 2 3 4 2 1] 10} ’=’ [10 20 30 40 20 10]} {Test {ScalarMultiply [2 3 4 2 1] 10} ’=’ [20 30 40 20 10]}
% This is file DepthTest.oz {Test {Depth baseT(int)} ’==>’ 0} {Test {Depth baseT(float)} ’==>’ 0} {Test {Depth productT(left: baseT(int) right: baseT(float))} ’==>’ 1} {Test {Depth productT(left: listT(baseT(int)) right: baseT(float))} ’==>’ 2} {Test {Depth productT(left: baseT(int) right: productT(left: baseT(float) right: baseT(bool)))} ’==>’ 2} {Test {Depth listT(productT(left: baseT(int) right: baseT(float)))} ’==>’ 2} {Test {Depth listT(productT(left: listT(baseT(int)) right: baseT(float)))} ’==>’ 3} {Test {Depth listT(productT(left: listT(baseT(int)) right: listT(listT(baseT(float)))))} ’==>’ 4}
declare fun {Depth TE} {FoldTExp TE fun {$ _} 0 end fun {$ LD RD} 1 + {Max LD RD} end fun {$ D} 1 + D end } end \insert ’DepthTest.oz’ % test cases for the Depth problem above
fun {Subst TE Old New} {FoldTExp TE fun {$ A} baseT( if A == Old then New else A end ) end fun {$ TL RT} productT(left: TL right: RT) end fun {$ LT} listT(LT) end } end \insert ’SubstTest.oz’ % test cases for the Subst problem above
fun {Count TE A} {FoldTExp TE fun {$ B} if B == A then 1 else 0 end end fun {$ LC RC} LC + RC end fun {$ C} C end } end {Test {Count baseT(int) int} ’==>’ 1} {Test {Count baseT(float) int} ’==>’ 0} {Test {Count listT(baseT(int)) int} ’==>’ 1} {Test {Count productT(left: baseT(bool) right: baseT(bool)) bool} ’==>’ 2} {Test {Count productT(left: productT(left: baseT(bool) right: listT(baseT(bool))) right: listT(baseT(bool))) bool} ’==>’ 3}