I've written a function that will compare two lists and check to see if the first is a prefix of the second and it must be done using recursion.
For example:
prefix [1,2] [1,2,3]
>True
prefix [2,1,4] [2,1,13,4]
>False
Now I've done this but I feel it's inefficient:
prefix :: [Int] -> [Int] -> Bool
prefix (x:xs) (y:ys)
| null xs = True
| x == y && head xs == head ys = True && prefix xs ys
| head xs /= head ys = False
I was hoping it could be done more efficiently and with some better pattern matching. Can it be?
-fwarn-incomplete-patternsor just-Wall. Typically, write{-# OPTIONS_GHC -Wall #-}way up at the top of the file.