Scrapbook-0.4.0: code examples
Copyright© Frank Jung 2022
LicenseGPL-3
Safe HaskellSafe-Inferred
LanguageHaskell2010

Weekday

Description

A simple demonstration on how to map to and from a bounded, enumerated data type.

In this example we use the weekdays names as our type to iterate across.

The makeWeekday code is rather weak as any word where the first 3 letters map to a weekday is valid for conversion.

Other Examples

Using enum:

This example shows how use Weekday from an enumeration:

>>> toEnum 0 :: WeekDay
Mon
Synopsis

Documentation

data Weekday Source #

Abbreviated days of the week from Mon (Monday) to Sun (Sunday).

Constructors

Mon 
Tue 
Wed 
Thu 
Fri 
Sat 
Sun 

Instances

Instances details
Arbitrary Weekday Source #

Provide a random instance of a Weekday.

This is for ease of use in property testing.

>>> generate arbitrary :: IO Weekday
Wed
Instance details

Defined in Weekday

Bounded Weekday Source # 
Instance details

Defined in Weekday

Enum Weekday Source # 
Instance details

Defined in Weekday

Read Weekday Source # 
Instance details

Defined in Weekday

Show Weekday Source # 
Instance details

Defined in Weekday

Eq Weekday Source # 
Instance details

Defined in Weekday

Methods

(==) :: Weekday -> Weekday -> Bool #

(/=) :: Weekday -> Weekday -> Bool #

makeWeekday :: String -> Maybe Weekday Source #

Read a Weekday from a String.

Some string to Weekday examples:

>>> makeWeekday "tHU"
Just Thu
>>> makeWeekday "sun"
Just Sun
>>> makeWeekday "Bad"
Nothing

Any string bigger than 3 characters also fails: >>> makeWeekday Mond Nothing

fullWeek :: [Weekday] Source #

List all days of the week.

>>> fullWeek
[Mon,Tue,Wed,Thu,Fri,Sat,Sun]

capitalise :: String -> String Source #

Return title case of string.

>>> capitalise "monday"
"Monday"
>>> null (capitalise "")
True