Suppose we use a skew binary tree representation for a list. When the list contains the data [10,20,30,...,100], its internal structure is as follows.
Complete the following class definition by writing the >>= function for the Maybe type.
data Maybe a = Just a | Nothing instance Monad (Maybe a) where return x = Just x
Write a function main with type IO () which reads two lines from the user and prints them back in reverse.
Explain the significance of strictness analysis to compiling Haskell programs into efficient code.
Suppose we have a parent predicate defined in Prolog.
Define a Prolog predicate sibling(A,B) based on the parent predicate that represents whether A and B are siblings.parent(Cheri, Carl). parent(Cheri, Hal). parent(Chuck, Carl). parent(Dorothy, Cheri). parent(Dorothy, Vicki).
data Maybe a = Just a | Nothing instance Monad (Maybe a) where return x = Just x Nothing >>= f = Nothing (Just x) >>= f = Just (f x)
main = do first <- getLine second <- getLine putStrLn second putStrLn first
sibling(A, B) :- parent(X, A), parent(X, B).