Last active
December 1, 2022 07:20
-
-
Save AndrasKovacs/ec65e07c713195087662c58398796501 to your computer and use it in GitHub Desktop.
Syntax proposal for or-patterns in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Examples | |
data Foo = A | B | C | |
foo :: Foo -> Int | |
foo A = 10 | |
foo B | |
foo C = 20 | |
foo :: Foo -> Int | |
foo x = case x of | |
A -> 10 | |
B | |
C -> 20 | |
foo :: Foo -> Int | |
foo x = case x of A -> 10; B; C -> 20 | |
foo :: Foo -> Int | |
foo x = case x of | |
A -> 10; | |
B;C -> 20 | |
foo :: Foo -> Int | |
foo = \case A -> 10; B;C -> 20 | |
-- pattern vars | |
data Foo = A Int | B Int | C Int | |
foo :: Foo -> Int | |
foo (A n) | |
foo (B n) | |
foo (C n) = n + 10 | |
foo :: Foo -> Int | |
foo = \case A n; B n; C n -> n + 10 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment