Skip to content

Instantly share code, notes, and snippets.

@dszakallas
Last active February 9, 2017 20:56
Show Gist options
  • Save dszakallas/7e5902396b85f797ab055a9c6c04f01a to your computer and use it in GitHub Desktop.
Save dszakallas/7e5902396b85f797ab055a9c6c04f01a to your computer and use it in GitHub Desktop.
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
deriving (Eq, Ord, Show, Read, Bounded, Enum)
-- and that's it. we have everything we need
-- david@mac:~% stack ghci
-- λ> Monday == Tuesday
-- False
-- λ> Monday == Monday
-- True
-- λ> Tuesday > Monday
-- True
-- λ> minBound :: Day
-- Monday
-- λ> maxBound :: Day
-- Sunday
-- λ> import qualified Data.Set as Set
-- λ> let orderedSet = Set.toList . foldl (flip Set.insert) Set.empty
-- λ> orderedSet [Wednesday, Wednesday, Monday, Tuesday, Friday]
-- [Monday,Tuesday,Wednesday,Friday]
-- λ> read "Monday" :: Day
-- Monday
-- λ> show Tuesday
-- "Tuesday"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment