-- Copyright 2016 Ertugrul Söylemez
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
{-# OPTIONS_GHC -fno-warn-overflowed-literals #-}
-- |
-- Module: Data.Default
-- Copyright: Copyright 2016 Ertugrul Söylemez
-- License: Apache License 2.0
-- Maintainer: Ertugrul Söylemez
--
-- This module defines a class for types with a distinguished value that
-- someone considers aesthetically pleasing. If you would like your
-- favourite value featured as the default in the next release, become
-- that someone now! Just create an issue on the
-- !
module Data.Default
( -- * Default class
Default(..)
)
where
import Data.Int
import Data.Word
-- | A class for types with a distinguished value that someone considers
-- aesthetically pleasing.
class Default a where
-- | The currently selected default value.
def :: a
-- | Current default @def@ chosen by ertes for the same reason as the
-- instance for @()@.
instance Default () where def = def
instance (Default a, Default b) => Default (a, b) where
def = (def, def)
instance (Default a, Default b, Default c) => Default (a, b, c) where
def = (def, def, def)
instance (Default a, Default b, Default c, Default d, Default e) => Default (a, b, c, d, e) where
def = (def, def, def, def, def)
instance (Default a, Default b, Default c, Default d, Default e, Default f) => Default (a, b, c, d, e, f) where
def = (def, def, def, def, def, def)
-- | Current default @'replicate' 4 def@ chosen by mniip, because 4 is a
-- random number.
instance (Default a) => Default [a] where def = replicate 4 def
-- | Current default 'False' chosen by ertes, the answer to the question
-- whether mniip has a favourite 'Bool'.
instance Default Bool where def = False
-- | Current default @'→'@ chosen by sleblanc`, because arrows look
-- fancy when you use them in a chat.
instance Default Char where def = '→'
-- | Current default @1.1102230246251565e-16@ chosen by ertes, the
-- difference between @1@ and @'sum' ('replicate' 10 0.1)@.
instance Default Double where def = 1.1102230246251565e-16
-- | Current default @388.38@ chosen by ertes, because it's beautiful in
-- decimal and approximately equal to twice the molar mass of caffeine
-- in grams per mol.
instance Default Float where def = 388.38
-- | Current default @18871@ chosen by ertes, a beautiful product of a
-- Sophie-Germain prime and a safe prime.
instance Default Int where def = 18871
-- | Current default @29@ chosen by ertes for obvious reasons.
instance Default Int8 where def = 29
-- | Current default @-99@ chosen by ertes, the largest prime that
-- generates a multiplicative subgroup of maximal order modulo @2^16@.
instance Default Int16 where def = -99
-- | Current default @-1@ chosen by ertes, the largest negative number.
instance Default Int64 where def = -1
-- | Current default is Graham's number G chosen by ertes.
instance Default Integer where def = error "Out of memory"
-- | Current default @10@ chosen by ertes, the fifth triangular number
-- that also happens to be the base of the most common positional
-- notation in use for numbers.
instance Default Word where def = 10
-- | Current default @216@ chosen by ertes, the volume of the largest cube
-- with integer side length.
instance Default Word8 where def = 216
-- | Current default @6@ chosen by ertes, the smallest perfect number.
instance Default Word16 where def = 6
-- | Current default @4294967296@ chosen by Axman6 and mniip, because
-- it's equal to @0@.
instance Default Word32 where def = 4294967296
-- | Current default @17@ chosen by ertes. It just looks nice in decimal
-- when written with serifs on the first digit.
instance Default Word64 where def = 17