Stream: beginners

Topic: ✔ How do I match on lists?


view this post on Zulip njlr (Jan 12 2024 at 20:25):

Weirdly this is not covered in the examples or docs

let sum items =
    when items is
        [] -> 0
        x :: xs -> x + (sum xs)

This part x :: xs isn't right.

What should it be?

view this post on Zulip Sven van Caem (Jan 12 2024 at 20:27):

I believe it'd be [x, .. as xs]!

view this post on Zulip njlr (Jan 12 2024 at 20:28):

That's the one! thanks

view this post on Zulip Notification Bot (Jan 12 2024 at 20:28):

njlr has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC