Created
June 7, 2020 23:30
-
-
Save wpcarro/300efd0128fa7c4a99043b2443be4a17 to your computer and use it in GitHub Desktop.
Enumerating Haskell data constructors
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
| module Extras where | |
| -- | Create a list of all of the data constructors for a given type. | |
| enumAll :: (Bounded a, Enum a) => [a] | |
| enumAll = [minBound .. ] |
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
| module Scratch where | |
| import Extras (enumAll) | |
| data OS | |
| = GnuPlusLinux | |
| | OpenBSD | |
| | Mac | |
| | Windows | |
| deriving (Eq, Show, Bounded, Enum) | |
| data ProgLang | |
| = Haskell | |
| | Agda | |
| | Idris | |
| | PureScript | |
| deriving (Eq, Show, Bounded, Enum) | |
| data Programmer | |
| = Programmer | |
| { os :: OS | |
| , pl :: ProgLang | |
| } deriving (Eq, Show) | |
| -- | Create a list of all possible programmers. | |
| programmers :: [Programmer] | |
| programmers = | |
| [Programmer os pl | os <- enumAll, pl <- enumAll] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment