Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@frontsideair
Created May 31, 2020 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frontsideair/992822ec150d6df472872eeb31030288 to your computer and use it in GitHub Desktop.
Save frontsideair/992822ec150d6df472872eeb31030288 to your computer and use it in GitHub Desktop.
List members of union in PureScript
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