[Proposal] As-patterns from haskell

53 views
Skip to first unread message

Corvo Liu

unread,
Jun 7, 2023, 11:36:31 PM6/7/23
to elixir-lang-core
In haskell there's a syntax sugar called as pattern. For example:

```
f (x:xs)                = x:x:xs
```

maybe rewrite as:

```
f s@(x:xs)             = x:s
```

This feature is useful, and I constantly find there's places in my code that I can use it to make my code more concise.

Andrey Yugai

unread,
Jun 7, 2023, 11:54:19 PM6/7/23
to elixir-l...@googlegroups.com

Could you provide an elixir example with proposed new syntax, for those who is not familiar with haskell?




-------- Original Message --------
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/afbf8a08-354c-48f1-a944-3683a3d0f236n%40googlegroups.com.

Corvo Liu

unread,
Jun 8, 2023, 12:14:33 AM6/8/23
to elixir-lang-core
NVM I found elixir can do this straightforwardly with a sequence of pattern:
```
a = {c, _} = {1, 2}
```
Reply all
Reply to author
Forward
0 new messages