[Haskell-beginners] A simple function V2
Brent Yorgey
byorgey at seas.upenn.edu
Fri Aug 31 15:52:40 CEST 2012
On Fri, Aug 31, 2012 at 09:01:30AM -0300, Ezequiel Hernan Di Giorgi wrote:
>
> *intercalate :: (Eq t) => [t] -> [t] -> [t]*
> *intercalate (x:xs) (y:ys)*
> * | xt == [] = []*
> * | yt == [] = []*
> * | otherwise = x : y : intercalate xs ys*
> * where xt=(x:xs)*
> * yt=(y:ys)*
I should also point out that the tests xt == [] and yt == [] will
never be true! That is because xt is defined to be (x:xs) and yt is
(y:ys). A list can be *either* the empty list [], or a cons like
(x:xs), but not both.
-Brent
More information about the Beginners
mailing list