Last active
May 8, 2019 02:26
-
-
Save evaporei/b71492741ee2e3845e6288fcdf822747 to your computer and use it in GitHub Desktop.
Haskell help, pattern match list of variants
This file contains hidden or 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
data Alphabet = A Int | B Float | C String | |
cool :: [Alphabet] -> Bool | |
cool [] = error "Should not call `cool` with empty list" | |
cool alphabetList = case alphabetList of | |
[A] -> coolInt alphabetList | |
[B] -> coolFloat alphabetList | |
[C] -> coolString alphabetList | |
_ -> error "Shouldn't call `cool` with list of different variants" | |
-- suppose there are coolInt, coolFloat and coolString functions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment