Pattern matching in function heads #196

Closed
opened 2019-12-09 21:27:10 +09:00 by zxq9 · 4 comments
zxq9 commented 2019-12-09 21:27:10 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

From the Sophia discussion at the Sofia workshop.

*Created by: UlfNorell* *From the Sophia discussion at the Sofia workshop.*
zxq9 commented 2019-12-09 21:28:35 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

The current syntax (mixing left-hand sides and type signatures) is not well suited for this. We could imagine allowing separate type signatures and multiple clauses:

  entrypoint
    foo : (int, string) => string
    foo(0, s) = s
    foo(n, s) = foo(n - 1, String.concat(s, s))
*Created by: UlfNorell* The current syntax (mixing left-hand sides and type signatures) is not well suited for this. We could imagine allowing separate type signatures and multiple clauses: ```sophia entrypoint foo : (int, string) => string foo(0, s) = s foo(n, s) = foo(n - 1, String.concat(s, s)) ```
zxq9 commented 2019-12-10 01:19:15 +09:00 (Migrated from gitlab.com)

Created by: radrow

I love this

*Created by: radrow* I love this
zxq9 commented 2019-12-11 08:44:14 +09:00 (Migrated from gitlab.com)

Created by: nikita-fuchs

I sense a strong smell of erlang in here - wouldn't this defacto lever out all strict type checking and allow for fallback functions taking whatever data ?

*Created by: nikita-fuchs* I sense a strong smell of erlang in here - wouldn't this defacto lever out all strict type checking and allow for fallback functions taking whatever data ?
zxq9 commented 2019-12-11 15:14:26 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

What, no! Why would you think this would change the type system? The above is the same as

entrypoint foo(a : int, s : string) =
  switch(a)
    0 => s
    n => foo(n - 1, String.concat(s, s)
*Created by: UlfNorell* What, no! Why would you think this would change the type system? The above is the same as ```sophia entrypoint foo(a : int, s : string) = switch(a) 0 => s n => foo(n - 1, String.concat(s, s) ```
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#196
No description provided.