[Haskell-beginners] As pattern, @

Ut Primum utprimum at gmail.com
Wed Jan 27 06:14:35 UTC 2021


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 at gmail.com> ha scritto:

> I'm looking at this <https://wiki.haskell.org/99_questions/Solutions/8>
> 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20210127/f9cdec9f/attachment.html>


More information about the Beginners mailing list