Skip to content

Instantly share code, notes, and snippets.

@evaporei
Last active May 8, 2019 02:26
Show Gist options
  • Save evaporei/b71492741ee2e3845e6288fcdf822747 to your computer and use it in GitHub Desktop.
Save evaporei/b71492741ee2e3845e6288fcdf822747 to your computer and use it in GitHub Desktop.
Haskell help, pattern match list of variants
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