Question: Remember the `zip` function of Haskell? It can be defined in Haskell as: zip :: [a] -> [b] -> [(a,b)] zip _ [] = []
Remember the `zip` function of Haskell? It can be defined in Haskell as: zip :: [a] -> [b] -> [(a,b)] zip _ [] = [] zip [] _ = [] zip (x:xs) (y:ys) = (x,y) : zip xs ys
Formulate the appropriate Prolog rule `zip(Xs,Ys,Zs)` which is true if (and only if) `Zs` is the result of "zipping" together `Xs` and `Ys`.
That is, the query `zip([1,2,3],[4,5],[(1,4),(2,5)]).` would evaluate to `true`, or the query `zip([1,2],[4,5,6],Zs).` would give `Zs = [(1,4),(2,5)]`.
Hint: again, this rule will have two base cases and a recursive case analogous to the above Haskell function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
