Give the type of the following functions/expressions:
fun fribble g x y = g(x,y);
fun frubble a b = (a+b,a-b);
fun zappit f [] = [] |
zappit f (a::b) = (f a)::(zappit f b);
Write an ML implementation of the following ML signature:
signature ZOSE = sig
type 'a zat
val zem: 'a zat
fun zip: 'a -> 'a zat -> 'a zat
fun zop: 'a zat -> 'a
fun zest: 'a zat -> 'a zat
end
it should be the case that:
zop(zem) = ERROR
zop(zip a x) = a
zest(zem) = zem
zest(zip a x) = x
For the grammar:
S -> Saab | aaSb | aabS | baa
which of the following are valid sentences:
a) aabbaa
b) baabaa
c) aaaaaabbb
d) aaabbb
Demonstrate the following grammar is ambiguous:
E -> E + E | E * E | E -E | x | y | z
- Implement the function sorted: (('a,'a) -> bool) -> 'a list -> bool
which applies it's first argument (the function) to each pair pf consecutive items in the list; and returns true if the function returns true for each consecutive pair.
Assume we have a database of prolog statements of the following format: (actor, movie, year); here are a few samples:
(kevin bacon, animal house, 1978)
(kevin bacon, diner, 1982)
(kevin bacon, footloose, 1984)
Write the prolog statement to determine "three degrees of Kevin Bacon";
that is to check whether, for a given actor, there is a pair of other
(distinct) actors who co-starred in some movie, such that one of those
actors co-starred with Kevin Bacon, and the other co-starred with the
"given" actor (in a third distinct movie).
Write the prolog function which will delete the first instance of an element from a list.
delete1st(7,[1,7,3,7],[1,3,7) would yield true
delete1st(5,[2,3,5,5], Y) would yield Y|[2,3,5]
Convert EBNF -> BNF
Blist -> { var (^ | \/ | => \) } var
-
Write the regular expressions:
For 8 digit (year,month,day) dates:
20250304 is valid
20251313 is not valid
19880734 is not valid
20250219 is valid
19991231 is valid
-
Write the grammar such that, every string contains only a and/or b:
And, no "b" occurs before any "a"