Examples-0.1.0: Haskell code examples
Copyright© Frank Jung 2023-2024
LicenseGPL-3.0-only
Safe HaskellSafe-Inferred
LanguageHaskell2010

Greeting

Description

 
Synopsis

Types

newtype Name Source #

Name type.

Constructors

Name 

Fields

Instances

Instances details
Show Name Source # 
Instance details

Defined in Greeting

Methods

showsPrec :: Int -> Name -> ShowS #

show :: Name -> String #

showList :: [Name] -> ShowS #

Eq Name Source # 
Instance details

Defined in Greeting

Methods

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

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

newtype Salutation Source #

Salutation type.

Constructors

Salutation 

Instances

Instances details
Show Salutation Source # 
Instance details

Defined in Greeting

Eq Salutation Source # 
Instance details

Defined in Greeting

data GreetingMessage Source #

Greeting message type. It consists of a salutation, a name to greet, and a list of names from whom the greeting is from.

Instances

Instances details
Show GreetingMessage Source # 
Instance details

Defined in Greeting

Eq GreetingMessage Source # 
Instance details

Defined in Greeting

class Redacted a where Source #

Redacted type class.

Minimal complete definition

Nothing

Methods

redacted :: a -> String Source #

default redacted :: Show a => a -> String Source #

Instances

Instances details
Redacted AdminUser Source # 
Instance details

Defined in Greeting

Redacted Common Source #

Common type instance of Redacted. This will echo the string as is.

Instance details

Defined in Greeting

Redacted Secret Source #

Redacted will not show string value for this Secret type.

Instance details

Defined in Greeting

Redacted UserName Source # 
Instance details

Defined in Greeting

newtype Common Source #

Common type.

Constructors

Common String 

Instances

Instances details
Redacted Common Source #

Common type instance of Redacted. This will echo the string as is.

Instance details

Defined in Greeting

Show Common Source #

Override Show instance to echo result with out type signature. A better way is to use GeneralizedNewtypeDeriving extension to derive the Show instance. This Show instance does not show the type.

Instance details

Defined in Greeting

newtype Secret Source #

Secret type.

Constructors

Secret String 

Instances

Instances details
Redacted Secret Source #

Redacted will not show string value for this Secret type.

Instance details

Defined in Greeting

newtype UserName Source #

Simpler way to implement Redacted instance for Secret. Needs the DeriveAnyClass extension. Overrides Show instance to give a customised value.

Constructors

UserName String 

Instances

Instances details
Redacted UserName Source # 
Instance details

Defined in Greeting

Show UserName Source # 
Instance details

Defined in Greeting

Eq UserName Source # 
Instance details

Defined in Greeting

newtype AdminUser Source #

AdminUer type. Will override Redacted instance to give a customised value.

Constructors

AdminUser UserName 

Instances

Instances details
Redacted AdminUser Source # 
Instance details

Defined in Greeting

Show AdminUser Source # 
Instance details

Defined in Greeting

Eq AdminUser Source # 
Instance details

Defined in Greeting

Functions

defaultMessage :: GreetingMessage Source #

Default greeting message.

defaultMessage {
    greetingSalutation :: Salutation "Hello"
  , greetingTo         :: Name "World"
  , greetingFrom       :: []}
}

formatMessage :: GreetingMessage -> String Source #

Format greeting message.

>>> formatMessage defaultMessage
"Hello, World!"
>>> formatMessage (defaultMessage {greetingTo = Name "Robyn", greetingFrom = [Name "Frank"]})
"Hello, Robyn! from Frank"