hmt-0.16: Haskell Music Theory

Safe HaskellSafe
LanguageHaskell98

Music.Theory.Read

Contents

Description

Read functions.

Synopsis

Documentation

reads_to_read_precise :: ReadS t -> String -> Maybe t Source #

Transform ReadS function into precise Read function. Requires using all the input to produce a single token. The only exception is a singular trailing white space character.

read_maybe :: Read a => String -> Maybe a Source #

reads_to_read_precise of reads. space character.

read_def :: Read a => a -> String -> a Source #

Variant of read_maybe with default value.

map (read_def 0) ["2","2:","2\n"] == [2,0,2]

read_err :: Read a => String -> a Source #

Variant of read_maybe that errors on Nothing.

reads_exact :: Read a => String -> Maybe a Source #

Variant of reads requiring exact match, no trailing white space.

map reads_exact ["1.5","2,5"] == [Just 1.5,Nothing]

reads_exact_err :: Read a => String -> String -> a Source #

Variant of reads_exact that errors on failure.

Type specific variants

read_integral_allow_commas_maybe :: Read i => String -> Maybe i Source #

Allow commas as thousand separators.

let r = [Just 123456,Just 123456,Nothing,Just 123456789]
in map read_integral_allow_commas_maybe ["123456","123,456","1234,56","123,456,789"]

read_ratio_with_div_err :: (Integral i, Read i) => String -> Ratio i Source #

Read a ratio where the division is given by / instead of % and the integers allow commas.

map read_ratio_with_div_err ["123,456/7","123,456,789"] == [123456/7,123456789]

read_ratio_allow_commas_err :: (Integral i, Read i) => String -> String -> Ratio i Source #

Read Ratio, allow commas for thousand separators.

read_ratio_allow_commas_err "327,680" "177,147" == 327680 / 177147

delete_trailing_point :: String -> String Source #

Delete trailing ., read fails for 700..

read_fractional_allow_trailing_point_err :: Read n => String -> n Source #

read_err disallows trailing decimal points.

map read_fractional_allow_trailing_point_err ["123.","123.4"] == [123.0,123.4]

Plain type specialisations

read_maybe_int :: String -> Maybe Int Source #

Type specialised read_maybe.

map read_maybe_int ["2","2:","2\n"] == [Just 2,Nothing,Just 2]

read_int :: String -> Int Source #

Type specialised read_err.

read_double :: String -> Double Source #

Type specialised read_err.

read_maybe_rational :: String -> Maybe Rational Source #

Type specialised read_maybe.

map read_maybe_rational ["1","1%2","1/2"] == [Nothing,Just (1/2),Nothing]

read_rational :: String -> Rational Source #

Type specialised read_err.

read_rational "1%4"

Numeric variants

read_hex_err :: (Eq n, Num n) => String -> n Source #

Error variant of readHex.

read_hex_err "F0B0" == 61616