
26 Dec
2015
26 Dec
'15
9:46 a.m.
Hi Fabien,
On Sat, 26 Dec 2015 15:19:17 +0100
Fabien R
extractIfBegins x [xs] | [xs] == (x:ys) = [ys] | otherwise = [xs]
But ghci complains that ys is not defined.
That is because you cannot pattern match whilst equality testing. The statement xs == (x:ys) is problematic therefore. You expect the compiler to see "oh, I don't know ys, but xs is a list, so I'm just checking x and put the rest into ys while I'm at it".
Without giving the answer, can someone give a hint about the approach to follow ?
Try pattern matching on the list xs instead. Also take care that it's xs, not [xs] (the latter notation implies a list with one element xs). Best, Max