Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
## DESCRIPTION
## Generates a sequence of val declarations in ML and asks for the
## final values.
## ENDDESCRIPTION

## DBsubject(Programming Languages)
## DBchapter(ML)
## DBsection(Data Structures)
## Date(12/04/2021)
## Institution(Louisiana Tech)
## Author(Jason Terry)
## Level(2)
## KEYWORDS('programming languages','ml','sml','expressions','val')


DOCUMENT();

## Load libraries
loadMacros(
"PGstandard.pl",
"PGcourse.pl",
"contextArbitraryString.pl",
"PGML.pl"
);

## Change context to strings answers
Context("Numeric");

## Create random parameters
$n1 = random(2,5,1);
$n2 = random(6,9,1);

## Create answers to problems
$a = $n1;
$b = $n2;
$b = $a + $b;
$c = $a*$b;
$a = $c - $a;
$c = $c + $a;

## Display question
TEXT(beginproblem());

BEGIN_PGML
Determine the final value of the all variables after all the following ML value declarations.

*val a = [$n1];*

*val b = [$n2];*

*val b = a + b;*

*val c = a \* b;*

*val a = c - a;*

*val c = c + a;*

FINAL VALUE OF ALL VARIABLES:

a = [__________]{$a}

b = [__________]{$b}

c = [__________]{$c}

END_PGML

BEGIN_PGML_SOLUTION
Solution:

a = [$a]

b = [$b]

c = [$c]

END_PGML_SOLUTION

ENDDOCUMENT();
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
## DESCRIPTION
## Generates ML expressions using tuples and lists and asks for their types.
## ENDDESCRIPTION

## DBsubject(Programming Languages)
## DBchapter(ML)
## DBsection(Data Structures)
## Date(12/04/2025)
## Institution(Louisiana Tech)
## Author(Jason Terry)
## Level(2)
## KEYWORDS('programming languages','ml','sml','expressions','type','tuple','list')


DOCUMENT();

## Load libraries
loadMacros(
"PGstandard.pl",
"PGcourse.pl",
"contextArbitraryString.pl",
"PGML.pl"
);

## Change context to strings answers
Context("ArbitraryString");

## Create custom answer checker for ML types
$typeChecker = sub {
my ($correct,$student,$ansHash) = @_; # get correct and student MathObjects
$correct = $correct->string;
$student = $student->string;
$student =~ s/^ *(.*?) *$/$1/; # remove front/end whitespace
$student =~ s/ *~~* */~~*/g; # * shall have no space on each side
$student =~ s/~~( */~~(/g; # ( shall have no space after
$student =~ s/ *~~)/~~)/g; # ) shall have no space before
$student =~ s/ *list/ list/g; # list shall have 1 space before
return ($correct eq $student); # return 1 if correct, 0 otherwise
};

$a = random(1,20,1);
$b = random(1,20,1);
$c = random(1,20,1);

## Create answers to problems and install custom type checker
$ans1 = String("int*string")->cmp(
checker => $typeChecker
);

$ans2 = String("real*bool*char")->cmp(
checker => $typeChecker
);

$ans3 = String("(real*bool)*char")->cmp(
checker => $typeChecker
);

$ans4 = String("bool list")->cmp(
checker => $typeChecker
);

$ans5 = String("int list list")->cmp(
checker => $typeChecker
);


## Display question
TEXT(beginproblem());

BEGIN_PGML
Write the type of the following ML expressions. *WARNING: Only use required parentheses for types to match the ML compiler's response.*

*([$a], \"hello\") : [_________________________]{$ans1}*
===
*([$b].4, true, #\"q\") : [_________________________]{$ans2}*
===
*(([$b].4, true), #\"q\") : [_________________________]{$ans3}*
===
*\[false\] : [_________________________]{$ans4}*
===
*\[\[[$c]\]\] : [_________________________]{$ans5}*


END_PGML

BEGIN_PGML_SOLUTION
Solution:

*([$a],\"hello\") : int\*string*
===
*([$b].4,true,#\"q\") : real\*bool\*char*
===
*(([$b].4,true),#\"q\") : (real\*bool)\*char*
===
*\[false\] : bool list*
===
*\[\[[$c]\]\] : int list list*


END_PGML_SOLUTION

ENDDOCUMENT();
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
## DESCRIPTION
## Generates ML expressions using tuples and lists and asks for their types.
## ENDDESCRIPTION

## DBsubject(Programming Languages)
## DBchapter(ML)
## DBsection(Data Structures)
## Date(12/04/2025)
## Institution(Louisiana Tech)
## Author(Jason Terry)
## Level(2)
## KEYWORDS('programming languages','ml','sml','expressions','type','tuple','list')


DOCUMENT();

## Load libraries
loadMacros(
"PGstandard.pl",
"PGcourse.pl",
"contextArbitraryString.pl",
"PGML.pl"
);

## Change context to strings answers
Context("ArbitraryString");

## Create custom answer checker for ML types
$typeChecker = sub {
my ($correct,$student,$ansHash) = @_; # get correct and student MathObjects
$correct = $correct->string;
$student = $student->string;
$student =~ s/^ *(.*?) *$/$1/; # remove front/end whitespace
$student =~ s/ *~~* */~~*/g; # * shall have no space on each side
$student =~ s/~~( */~~(/g; # ( shall have no space after
$student =~ s/ *~~)/~~)/g; # ) shall have no space before
$student =~ s/ *list/ list/g; # list shall have 1 space before
return ($correct eq $student); # return 1 if correct, 0 otherwise
};

$a = random(1,20,1);
$b = random(1,20,1);
$c = random(1,20,1);

## Create answers to problems and install custom type checker
$ans1 = String("int*int")->cmp(
checker => $typeChecker
);

$ans2 = String("int list*int")->cmp(
checker => $typeChecker
);

$ans3 = String("(int*int) list")->cmp(
checker => $typeChecker
);

$ans4 = String("real*(string*int list)")->cmp(
checker => $typeChecker
);

$ans5 = String("((int*int)*int) list")->cmp(
checker => $typeChecker
);


## Display question
TEXT(beginproblem());

BEGIN_PGML
Write the type of the following ML expressions. *WARNING: Only use required parentheses for types to match the ML compiler's response.*

*([$a], [$b]) : [_________________________]{$ans1}*
===
*(\[[$a]\], [$b]) : [_________________________]{$ans2}*
===
*\[([$a],[$b])\] : [_________________________]{$ans3}*
===
*([$a].77,(\"[$b]\",\[[$c]\])) : [_________________________]{$ans4}*
===
*\[(([$a],[$b]),[$c])\] : [_________________________]{$ans5}*


END_PGML

BEGIN_PGML_SOLUTION
Solution:

*([$a],\"hello\") : int\*string*
===
*([$b].4,true,#\"q\") : real\*bool\*char*
===
*(([$b].4,true),#\"q\") : (real\*bool)\*char*
===
*\[false\] : bool list*
===
*\[\[[$c]\]\] : int list list*


END_PGML_SOLUTION

ENDDOCUMENT();
Loading