Hi,
between the arguments of a function,
ys@(y:yss)
would mean that we call that argument ys, we call its head y and its tail yss. In your case the tail is replaced by _ , because is never used inside the function.

Il mer 27 gen 2021, 07:02 Lawrence Bottorff <borgauf@gmail.com> ha scritto:
I'm looking at this and wondering how the "as pattern" actually is working

compress (x:ys@(y:_))
    | x == y    = compress ys
    | otherwise = x : compress ys
compress ys = ys

I'm sure it's just some version of my stab at eliminating consecutive duplicates in a list

compress :: Eq a => [a] -> [a]
compress [] = []
compress [x] = [x]
compress (x:y:xs) = if x == y then compress (y:xs) else x : compress (y:xs)

only smarter. Could someone walk me through the (x:ys@(y:_)) part?

LB


_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners