Created
May 31, 2020 13:18
-
-
Save frontsideair/992822ec150d6df472872eeb31030288 to your computer and use it in GitHub Desktop.
List members of union in PureScript
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
module Main where | |
import Prelude | |
import Data.Enum | |
import Data.Maybe | |
import Data.List | |
import Effect | |
import TryPureScript | |
data Size = Small | Medium | Large | |
instance showSize :: Show Size where | |
show Small = "small" | |
show Medium = "medium" | |
show Large = "large" | |
derive instance eqSize :: Eq Size | |
derive instance ordSize :: Ord Size | |
instance enumSize :: Enum Size where | |
succ Small = Just Medium | |
succ Medium = Just Large | |
succ Large = Nothing | |
pred Small = Nothing | |
pred Medium = Just Small | |
pred Large = Just Medium | |
instance boundedSize :: Bounded Size where | |
bottom = Small | |
top = Large | |
main :: Effect Unit | |
main = | |
render $ list (map textSize sizes) | |
where | |
sizes :: List Size | |
sizes = enumFromTo bottom top | |
textSize size = text (show size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment