| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Prelude.Linear
Description
This module provides a replacement for Prelude with
support for linear programming via linear versions of
standard data types, functions and type classes.
A simple example:
>>>:set -XLinearTypes>>>:set -XNoImplicitPrelude>>>import Prelude.Linear>>>:{boolToInt :: Bool %1-> Int boolToInt False = 0 boolToInt True = 1 :}
>>>:{makeInt :: Either Int Bool %1-> Int makeInt = either id boolToInt :}
This module is designed to be imported unqualifed.
Synopsis
- module Data.Bool.Linear
- data Char
- module Data.Maybe.Linear
- module Data.Either.Linear
- module Prelude.Linear.Internal.TypeEq
- fst :: (a, b) -> a
- snd :: (a, b) -> b
- curry :: ((a, b) %p -> c) %q -> a %p -> b %p -> c
- uncurry :: (a %p -> b %p -> c) %q -> (a, b) %p -> c
- module Data.Ord.Linear
- class Enum a where
- succ :: a -> a
- pred :: a -> a
- toEnum :: Int -> a
- fromEnum :: a -> Int
- enumFrom :: a -> [a]
- enumFromThen :: a -> a -> [a]
- enumFromTo :: a -> a -> [a]
- enumFromThenTo :: a -> a -> a -> [a]
- class Bounded a where
- data Int
- data Integer
- data Float
- data Double
- type Rational = Ratio Integer
- data Word
- module Data.Num.Linear
- class (Num a, Ord a) => Real a where
- toRational :: a -> Rational
- class (Real a, Enum a) => Integral a where
- class Fractional a => Floating a where
- class Num a => Fractional a where
- (/) :: a -> a -> a
- recip :: a -> a
- fromRational :: Rational -> a
- class (Real a, Fractional a) => RealFrac a where
- class (RealFrac a, Floating a) => RealFloat a where
- floatRadix :: a -> Integer
- floatDigits :: a -> Int
- floatRange :: a -> (Int, Int)
- decodeFloat :: a -> (Integer, Int)
- encodeFloat :: Integer -> Int -> a
- exponent :: a -> Int
- significand :: a -> a
- scaleFloat :: Int -> a -> a
- isNaN :: a -> Bool
- isInfinite :: a -> Bool
- isDenormalized :: a -> Bool
- isNegativeZero :: a -> Bool
- isIEEE :: a -> Bool
- atan2 :: a -> a -> a
- subtract :: Num a => a -> a -> a
- even :: Integral a => a -> Bool
- odd :: Integral a => a -> Bool
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- (^) :: (Num a, Integral b) => a -> b -> a
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- fromIntegral :: (Integral a, Num b) => a -> b
- realToFrac :: (Real a, Fractional b) => a -> b
- (<*) :: (Applicative f, Consumable b) => f a %1 -> f b %1 -> f a
- module Data.Monoid.Linear
- id :: a %q -> a
- const :: a %q -> b -> a
- (.) :: forall {rep} b (c :: TYPE rep) a q m n. (b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
- flip :: (a %p -> b %q -> c) %r -> b %q -> a %p -> c
- ($) :: forall {rep} a (b :: TYPE rep) p q. (a %p -> b) %q -> a %p -> b
- (&) :: forall {rep} a (b :: TYPE rep) p q. a %p -> (a %p -> b) %q -> b
- until :: (a -> Bool) -> (a -> a) -> a -> a
- error :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => [Char] -> a
- errorWithoutStackTrace :: forall (r :: RuntimeRep) (a :: TYPE r). [Char] -> a
- undefined :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => a
- seq :: a -> b %q -> b
- ($!) :: forall {rep} a (b :: TYPE rep) p q. (a %p -> b) %q -> a %p -> b
- module Data.List.Linear
- module Data.String
- type ShowS = String -> String
- class Show a where
- shows :: Show a => a -> ShowS
- showChar :: Char -> ShowS
- showString :: String -> ShowS
- showParen :: Bool -> ShowS -> ShowS
- type ReadS a = String -> [(a, String)]
- class Read a where
- reads :: Read a => ReadS a
- readParen :: Bool -> ReadS a -> ReadS a
- read :: Read a => String -> a
- lex :: ReadS String
- data IO a
- putChar :: Char -> IO ()
- putStr :: String -> IO ()
- putStrLn :: String -> IO ()
- print :: Show a => a -> IO ()
- getChar :: IO Char
- getLine :: IO String
- getContents :: IO String
- interact :: (String -> String) -> IO ()
- type FilePath = String
- readFile :: FilePath -> IO String
- writeFile :: FilePath -> String -> IO ()
- appendFile :: FilePath -> String -> IO ()
- readIO :: Read a => String -> IO a
- readLn :: Read a => IO a
- data Ur a where
- unur :: Ur a %1 -> a
- class Consumable a where
- consume :: a %1 -> ()
- class Consumable a => Dupable a where
- dupR :: a %1 -> Replicator a
- dup2 :: a %1 -> (a, a)
- class Dupable a => Movable a where
- lseq :: Consumable a => a %1 -> b %1 -> b
- dup :: Dupable a => a %1 -> (a, a)
- dup3 :: Dupable a => a %1 -> (a, a, a)
- forget :: forall {rep} a (b :: TYPE rep). (a %1 -> b) %1 -> a -> b
Standard Types, Classes and Related Functions
Basic data types
module Data.Bool.Linear
The character type Char is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) code points (i.e. characters, see
http://www.unicode.org/ for details). This set extends the ISO 8859-1
(Latin-1) character set (the first 256 characters), which is itself an extension
of the ASCII character set (the first 128 characters). A character literal in
Haskell has type Char.
To convert a Char to or from the corresponding Int value defined
by Unicode, use toEnum and fromEnum from the
Enum class respectively (or equivalently ord and
chr).
Instances
| Storable Char | Since: base-2.1 |
Defined in Foreign.Storable | |
| Bounded Char | Since: base-2.1 |
| Enum Char | Since: base-2.1 |
| Ix Char | Since: base-2.1 |
| Read Char | Since: base-2.1 |
| Show Char | Since: base-2.1 |
| Eq Char | |
| Ord Char | |
| Hashable Char | |
Defined in Data.Hashable.Class | |
| Eq Char Source # | |
| Ord Char Source # | |
| Consumable Char Source # | |
Defined in Data.Unrestricted.Linear.Internal.Consumable | |
| Dupable Char Source # | |
| Movable Char Source # | |
| Uniform Char | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Char # | |
| UniformRange Char | |
Defined in System.Random.Internal | |
| ErrorList Char | |
Defined in Control.Monad.Trans.Error | |
| Lift Char | |
| Generic1 (URec Char :: k -> Type) | |
| Foldable (UChar :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => UChar m -> m # foldMap :: Monoid m => (a -> m) -> UChar a -> m # foldMap' :: Monoid m => (a -> m) -> UChar a -> m # foldr :: (a -> b -> b) -> b -> UChar a -> b # foldr' :: (a -> b -> b) -> b -> UChar a -> b # foldl :: (b -> a -> b) -> b -> UChar a -> b # foldl' :: (b -> a -> b) -> b -> UChar a -> b # foldr1 :: (a -> a -> a) -> UChar a -> a # foldl1 :: (a -> a -> a) -> UChar a -> a # elem :: Eq a => a -> UChar a -> Bool # maximum :: Ord a => UChar a -> a # minimum :: Ord a => UChar a -> a # | |
| Traversable (UChar :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (UChar :: Type -> Type) Source # | |
| GTraversable (UChar :: TYPE LiftedRep -> Type) Source # | |
Defined in Data.Functor.Linear.Internal.Traversable Methods gtraverse :: Applicative f => (a %1 -> f b) -> UChar a %1 -> Curried (Yoneda f) (Yoneda f) (UChar b) | |
| Traversable (UChar :: Type -> Type) Source # | |
Defined in Data.Functor.Linear.Internal.Traversable | |
| Functor (URec Char :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
| Generic (URec Char p) | |
| Show (URec Char p) | Since: base-4.9.0.0 |
| Eq (URec Char p) | Since: base-4.9.0.0 |
| Ord (URec Char p) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type Rep Char | |
| data URec Char (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
| type Compare (a :: Char) (b :: Char) | |
Defined in Data.Type.Ord | |
| type Rep1 (URec Char :: k -> Type) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type Rep1 (URec Char :: k -> Type) | |
Defined in Generics.Linear.Instances.Base | |
| type Rep (URec Char p) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type Rep (URec Char p) | |
Defined in Generics.Linear.Instances.Base | |
module Data.Maybe.Linear
module Data.Either.Linear
Tuples
Basic type classes
module Data.Ord.Linear
Class Enum defines operations on sequentially ordered types.
The enumFrom... methods are used in Haskell's translation of
arithmetic sequences.
Instances of Enum may be derived for any enumeration type (types
whose constructors have no fields). The nullary constructors are
assumed to be numbered left-to-right by fromEnum from 0 through n-1.
See Chapter 10 of the Haskell Report for more details.
For any type that is an instance of class Bounded as well as Enum,
the following should hold:
- The calls
andsuccmaxBoundshould result in a runtime error.predminBound fromEnumandtoEnumshould give a runtime error if the result value is not representable in the result type. For example,is an error.toEnum7 ::BoolenumFromandenumFromThenshould be defined with an implicit bound, thus:
enumFrom x = enumFromTo x maxBound
enumFromThen x y = enumFromThenTo x y bound
where
bound | fromEnum y >= fromEnum x = maxBound
| otherwise = minBoundMethods
the successor of a value. For numeric types, succ adds 1.
the predecessor of a value. For numeric types, pred subtracts 1.
Convert from an Int.
Convert to an Int.
It is implementation-dependent what fromEnum returns when
applied to a value that is too large to fit in an Int.
Used in Haskell's translation of [n..] with [n..] = enumFrom n,
a possible implementation being enumFrom n = n : enumFrom (succ n).
For example:
enumFrom 4 :: [Integer] = [4,5,6,7,...]
enumFrom 6 :: [Int] = [6,7,8,9,...,maxBound :: Int]
enumFromThen :: a -> a -> [a] #
Used in Haskell's translation of [n,n'..]
with [n,n'..] = enumFromThen n n', a possible implementation being
enumFromThen n n' = n : n' : worker (f x) (f x n'),
worker s v = v : worker s (s v), x = fromEnum n' - fromEnum n and
f n y
| n > 0 = f (n - 1) (succ y)
| n < 0 = f (n + 1) (pred y)
| otherwise = y
For example:
enumFromThen 4 6 :: [Integer] = [4,6,8,10...]
enumFromThen 6 2 :: [Int] = [6,2,-2,-6,...,minBound :: Int]
enumFromTo :: a -> a -> [a] #
Used in Haskell's translation of [n..m] with
[n..m] = enumFromTo n m, a possible implementation being
enumFromTo n m
| n <= m = n : enumFromTo (succ n) m
| otherwise = [].
For example:
enumFromTo 6 10 :: [Int] = [6,7,8,9,10]
enumFromTo 42 1 :: [Integer] = []
enumFromThenTo :: a -> a -> a -> [a] #
Used in Haskell's translation of [n,n'..m] with
[n,n'..m] = enumFromThenTo n n' m, a possible implementation
being enumFromThenTo n n' m = worker (f x) (c x) n m,
x = fromEnum n' - fromEnum n, c x = bool (>=) ((x 0)
f n y
| n > 0 = f (n - 1) (succ y)
| n < 0 = f (n + 1) (pred y)
| otherwise = y and
worker s c v m
| c v m = v : worker s c (s v) m
| otherwise = []
For example:
enumFromThenTo 4 2 -6 :: [Integer] = [4,2,0,-2,-4,-6]
enumFromThenTo 6 8 2 :: [Int] = []
Instances
The Bounded class is used to name the upper and lower limits of a
type. Ord is not a superclass of Bounded since types that are not
totally ordered may also have upper and lower bounds.
The Bounded class may be derived for any enumeration type;
minBound is the first constructor listed in the data declaration
and maxBound is the last.
Bounded may also be derived for single-constructor datatypes whose
constituent types are in Bounded.
Instances
| Bounded All | Since: base-2.1 |
| Bounded Any | Since: base-2.1 |
| Bounded IntPtr | |
| Bounded WordPtr | |
| Bounded Associativity | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| Bounded DecidedStrictness | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| Bounded SourceStrictness | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| Bounded SourceUnpackedness | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| Bounded Int16 | Since: base-2.1 |
| Bounded Int32 | Since: base-2.1 |
| Bounded Int64 | Since: base-2.1 |
| Bounded Int8 | Since: base-2.1 |
| Bounded GeneralCategory | Since: base-2.1 |
Defined in GHC.Unicode | |
| Bounded Word16 | Since: base-2.1 |
| Bounded Word32 | Since: base-2.1 |
| Bounded Word64 | Since: base-2.1 |
| Bounded Word8 | Since: base-2.1 |
| Bounded Extension | |
| Bounded Ordering | Since: base-2.1 |
| Bounded () | Since: base-2.1 |
| Bounded Bool | Since: base-2.1 |
| Bounded Char | Since: base-2.1 |
| Bounded Int | Since: base-2.1 |
| Bounded Levity | Since: base-4.16.0.0 |
| Bounded VecCount | Since: base-4.10.0.0 |
| Bounded VecElem | Since: base-4.10.0.0 |
| Bounded Word | Since: base-2.1 |
| Bounded a => Bounded (Identity a) | Since: base-4.9.0.0 |
| Bounded a => Bounded (Down a) | Swaps Since: base-4.14.0.0 |
| Bounded a => Bounded (First a) | Since: base-4.9.0.0 |
| Bounded a => Bounded (Last a) | Since: base-4.9.0.0 |
| Bounded a => Bounded (Max a) | Since: base-4.9.0.0 |
| Bounded a => Bounded (Min a) | Since: base-4.9.0.0 |
| Bounded m => Bounded (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| Bounded a => Bounded (Dual a) | Since: base-2.1 |
| Bounded a => Bounded (Product a) | Since: base-2.1 |
| Bounded a => Bounded (Sum a) | Since: base-2.1 |
| Bounded a => Bounded (a) | |
| Bounded (Proxy t) | Since: base-4.7.0.0 |
| (Bounded a, Bounded b) => Bounded (a, b) | Since: base-2.1 |
| Bounded a => Bounded (Const a b) | Since: base-4.9.0.0 |
| (Applicative f, Bounded a) => Bounded (Ap f a) | Since: base-4.12.0.0 |
| a ~ b => Bounded (a :~: b) | Since: base-4.7.0.0 |
| (Bounded a, Bounded b, Bounded c) => Bounded (a, b, c) | Since: base-2.1 |
| a ~~ b => Bounded (a :~~: b) | Since: base-4.10.0.0 |
| (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a, b, c, d) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a, b, c, d, e) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f) => Bounded (a, b, c, d, e, f) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g) => Bounded (a, b, c, d, e, f, g) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h) => Bounded (a, b, c, d, e, f, g, h) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i) => Bounded (a, b, c, d, e, f, g, h, i) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j) => Bounded (a, b, c, d, e, f, g, h, i, j) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k) => Bounded (a, b, c, d, e, f, g, h, i, j, k) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | Since: base-2.1 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | Since: base-2.1 |
Numbers
A fixed-precision integer type with at least the range [-2^29 .. 2^29-1].
The exact range for a given implementation can be determined by using
minBound and maxBound from the Bounded class.
Instances
Arbitrary precision integers. In contrast with fixed-size integral types
such as Int, the Integer type represents the entire infinite range of
integers.
Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations.
If the value is small (fit into an Int), IS constructor is used.
Otherwise Integer and IN constructors are used to store a BigNat
representing respectively the positive or the negative value magnitude.
Invariant: Integer and IN are used iff value doesn't fit in IS
Instances
| Enum Integer | Since: base-2.1 |
| Ix Integer | Since: base-2.1 |
Defined in GHC.Ix | |
| Num Integer | Since: base-2.1 |
| Read Integer | Since: base-2.1 |
| Integral Integer | Since: base-2.0.1 |
Defined in GHC.Real | |
| Real Integer | Since: base-2.0.1 |
Defined in GHC.Real Methods toRational :: Integer -> Rational # | |
| Show Integer | Since: base-2.1 |
| Eq Integer | |
| Ord Integer | |
| Hashable Integer | |
Defined in Data.Hashable.Class | |
| UniformRange Integer | |
Defined in System.Random.Internal | |
| Lift Integer | |
Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.
Instances
| Storable Float | Since: base-2.1 |
| Floating Float | Since: base-2.1 |
| RealFloat Float | Since: base-2.1 |
Defined in GHC.Float Methods floatRadix :: Float -> Integer # floatDigits :: Float -> Int # floatRange :: Float -> (Int, Int) # decodeFloat :: Float -> (Integer, Int) # encodeFloat :: Integer -> Int -> Float # significand :: Float -> Float # scaleFloat :: Int -> Float -> Float # isInfinite :: Float -> Bool # isDenormalized :: Float -> Bool # isNegativeZero :: Float -> Bool # | |
| Read Float | Since: base-2.1 |
| Eq Float | Note that due to the presence of
Also note that
|
| Ord Float | Note that due to the presence of
Also note that, due to the same,
|
| Hashable Float | Note: prior to The Since: hashable-1.3.0.0 |
Defined in Data.Hashable.Class | |
| Consumable Float Source # | |
Defined in Data.Unrestricted.Linear.Internal.Consumable | |
| Dupable Float Source # | |
| Movable Float Source # | |
| UniformRange Float | |
Defined in System.Random.Internal | |
| Lift Float | |
| Generic1 (URec Float :: k -> Type) | |
| Foldable (UFloat :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => UFloat m -> m # foldMap :: Monoid m => (a -> m) -> UFloat a -> m # foldMap' :: Monoid m => (a -> m) -> UFloat a -> m # foldr :: (a -> b -> b) -> b -> UFloat a -> b # foldr' :: (a -> b -> b) -> b -> UFloat a -> b # foldl :: (b -> a -> b) -> b -> UFloat a -> b # foldl' :: (b -> a -> b) -> b -> UFloat a -> b # foldr1 :: (a -> a -> a) -> UFloat a -> a # foldl1 :: (a -> a -> a) -> UFloat a -> a # elem :: Eq a => a -> UFloat a -> Bool # maximum :: Ord a => UFloat a -> a # minimum :: Ord a => UFloat a -> a # | |
| Traversable (UFloat :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (UFloat :: Type -> Type) Source # | |
| GTraversable (UFloat :: TYPE LiftedRep -> Type) Source # | |
Defined in Data.Functor.Linear.Internal.Traversable Methods gtraverse :: Applicative f => (a %1 -> f b) -> UFloat a %1 -> Curried (Yoneda f) (Yoneda f) (UFloat b) | |
| Traversable (UFloat :: Type -> Type) Source # | |
Defined in Data.Functor.Linear.Internal.Traversable | |
| Functor (URec Float :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
| Generic (URec Float p) | |
| Show (URec Float p) | |
| Eq (URec Float p) | |
| Ord (URec Float p) | |
Defined in GHC.Generics | |
| type Rep Float | |
| data URec Float (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
| type Rep1 (URec Float :: k -> Type) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type Rep1 (URec Float :: k -> Type) | |
Defined in Generics.Linear.Instances.Base | |
| type Rep (URec Float p) | |
Defined in GHC.Generics | |
| type Rep (URec Float p) | |
Defined in Generics.Linear.Instances.Base | |
Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.
Instances
| Storable Double | Since: base-2.1 |
| Floating Double | Since: base-2.1 |
| RealFloat Double | Since: base-2.1 |
Defined in GHC.Float Methods floatRadix :: Double -> Integer # floatDigits :: Double -> Int # floatRange :: Double -> (Int, Int) # decodeFloat :: Double -> (Integer, Int) # encodeFloat :: Integer -> Int -> Double # significand :: Double -> Double # scaleFloat :: Int -> Double -> Double # isInfinite :: Double -> Bool # isDenormalized :: Double -> Bool # isNegativeZero :: Double -> Bool # | |
| Read Double | Since: base-2.1 |
| Eq Double | Note that due to the presence of
Also note that
|
| Ord Double | Note that due to the presence of
Also note that, due to the same,
|
| Hashable Double | Note: prior to The Since: hashable-1.3.0.0 |
Defined in Data.Hashable.Class | |
| AddIdentity Double Source # | |
Defined in Data.Num.Linear | |
| Additive Double Source # | |
| AdditiveGroup Double Source # | |
| FromInteger Double Source # | |
Defined in Data.Num.Linear Methods fromInteger :: Integer %1 -> Double Source # | |
| MultIdentity Double Source # | |
Defined in Data.Num.Linear | |
| Multiplicative Double Source # | |
| Num Double Source # | |
| Ring Double Source # | |
Defined in Data.Num.Linear | |
| Semiring Double Source # | |
Defined in Data.Num.Linear | |
| Eq Double Source # | |
| Ord Double Source # | |
| Consumable Double Source # | |
Defined in Data.Unrestricted.Linear.Internal.Consumable | |
| Dupable Double Source # | |
| Movable Double Source # | |
| UniformRange Double | |
Defined in System.Random.Internal | |
| Lift Double | |
| Generic1 (URec Double :: k -> Type) | |
| Foldable (UDouble :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => UDouble m -> m # foldMap :: Monoid m => (a -> m) -> UDouble a -> m # foldMap' :: Monoid m => (a -> m) -> UDouble a -> m # foldr :: (a -> b -> b) -> b -> UDouble a -> b # foldr' :: (a -> b -> b) -> b -> UDouble a -> b # foldl :: (b -> a -> b) -> b -> UDouble a -> b # foldl' :: (b -> a -> b) -> b -> UDouble a -> b # foldr1 :: (a -> a -> a) -> UDouble a -> a # foldl1 :: (a -> a -> a) -> UDouble a -> a # elem :: Eq a => a -> UDouble a -> Bool # maximum :: Ord a => UDouble a -> a # minimum :: Ord a => UDouble a -> a # | |
| Traversable (UDouble :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (UDouble :: Type -> Type) Source # | |
| GTraversable (UDouble :: TYPE LiftedRep -> Type) Source # | |
Defined in Data.Functor.Linear.Internal.Traversable Methods gtraverse :: Applicative f => (a %1 -> f b) -> UDouble a %1 -> Curried (Yoneda f) (Yoneda f) (UDouble b) | |
| Traversable (UDouble :: Type -> Type) Source # | |
Defined in Data.Functor.Linear.Internal.Traversable | |
| Functor (URec Double :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
| Generic (URec Double p) | |
| Show (URec Double p) | Since: base-4.9.0.0 |
| Eq (URec Double p) | Since: base-4.9.0.0 |
| Ord (URec Double p) | Since: base-4.9.0.0 |
Defined in GHC.Generics Methods compare :: URec Double p -> URec Double p -> Ordering # (<) :: URec Double p -> URec Double p -> Bool # (<=) :: URec Double p -> URec Double p -> Bool # (>) :: URec Double p -> URec Double p -> Bool # (>=) :: URec Double p -> URec Double p -> Bool # | |
| type Rep Double | |
| data URec Double (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
| type Rep1 (URec Double :: k -> Type) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type Rep1 (URec Double :: k -> Type) | |
Defined in Generics.Linear.Instances.Base | |
| type Rep (URec Double p) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type Rep (URec Double p) | |
Defined in Generics.Linear.Instances.Base | |
Instances
| Storable Word | Since: base-2.1 |
Defined in Foreign.Storable | |
| Bounded Word | Since: base-2.1 |
| Enum Word | Since: base-2.1 |
| Ix Word | Since: base-4.6.0.0 |
| Num Word | Since: base-2.1 |
| Read Word | Since: base-4.5.0.0 |
| Integral Word | Since: base-2.1 |
| Real Word | Since: base-2.1 |
Defined in GHC.Real Methods toRational :: Word -> Rational # | |
| Show Word | Since: base-2.1 |
| Eq Word | |
| Ord Word | |
| Hashable Word | |
Defined in Data.Hashable.Class | |
| Consumable Word Source # | |
Defined in Data.Unrestricted.Linear.Internal.Consumable | |
| Dupable Word Source # | |
| Movable Word Source # | |
| KnownRepresentable Word Source # | |
Defined in Foreign.Marshal.Pure.Internal | |
| Representable Word Source # | |
| Uniform Word | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Word # | |
| UniformRange Word | |
Defined in System.Random.Internal | |
| Lift Word | |
| Generic1 (URec Word :: k -> Type) | |
| Foldable (UWord :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => UWord m -> m # foldMap :: Monoid m => (a -> m) -> UWord a -> m # foldMap' :: Monoid m => (a -> m) -> UWord a -> m # foldr :: (a -> b -> b) -> b -> UWord a -> b # foldr' :: (a -> b -> b) -> b -> UWord a -> b # foldl :: (b -> a -> b) -> b -> UWord a -> b # foldl' :: (b -> a -> b) -> b -> UWord a -> b # foldr1 :: (a -> a -> a) -> UWord a -> a # foldl1 :: (a -> a -> a) -> UWord a -> a # elem :: Eq a => a -> UWord a -> Bool # maximum :: Ord a => UWord a -> a # minimum :: Ord a => UWord a -> a # | |
| Traversable (UWord :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (UWord :: Type -> Type) Source # | |
| GTraversable (UWord :: TYPE LiftedRep -> Type) Source # | |
Defined in Data.Functor.Linear.Internal.Traversable Methods gtraverse :: Applicative f => (a %1 -> f b) -> UWord a %1 -> Curried (Yoneda f) (Yoneda f) (UWord b) | |
| Traversable (UWord :: Type -> Type) Source # | |
Defined in Data.Functor.Linear.Internal.Traversable | |
| Functor (URec Word :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
| Generic (URec Word p) | |
| Show (URec Word p) | Since: base-4.9.0.0 |
| Eq (URec Word p) | Since: base-4.9.0.0 |
| Ord (URec Word p) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type AsKnown Word Source # | |
Defined in Foreign.Marshal.Pure.Internal | |
| type Rep Word | |
| data URec Word (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
| type Rep1 (URec Word :: k -> Type) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type Rep1 (URec Word :: k -> Type) | |
Defined in Generics.Linear.Instances.Base | |
| type Rep (URec Word p) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| type Rep (URec Word p) | |
Defined in Generics.Linear.Instances.Base | |
module Data.Num.Linear
class (Num a, Ord a) => Real a where #
Methods
toRational :: a -> Rational #
the rational equivalent of its real argument with full precision
Instances
| Real IntPtr | |
Defined in Foreign.Ptr Methods toRational :: IntPtr -> Rational # | |
| Real WordPtr | |
Defined in Foreign.Ptr Methods toRational :: WordPtr -> Rational # | |
| Real Int16 | Since: base-2.1 |
Defined in GHC.Int Methods toRational :: Int16 -> Rational # | |
| Real Int32 | Since: base-2.1 |
Defined in GHC.Int Methods toRational :: Int32 -> Rational # | |
| Real Int64 | Since: base-2.1 |
Defined in GHC.Int Methods toRational :: Int64 -> Rational # | |
| Real Int8 | Since: base-2.1 |
Defined in GHC.Int Methods toRational :: Int8 -> Rational # | |
| Real Word16 | Since: base-2.1 |
Defined in GHC.Word Methods toRational :: Word16 -> Rational # | |
| Real Word32 | Since: base-2.1 |
Defined in GHC.Word Methods toRational :: Word32 -> Rational # | |
| Real Word64 | Since: base-2.1 |
Defined in GHC.Word Methods toRational :: Word64 -> Rational # | |
| Real Word8 | Since: base-2.1 |
Defined in GHC.Word Methods toRational :: Word8 -> Rational # | |
| Real Integer | Since: base-2.0.1 |
Defined in GHC.Real Methods toRational :: Integer -> Rational # | |
| Real Natural | Since: base-4.8.0.0 |
Defined in GHC.Real Methods toRational :: Natural -> Rational # | |
| Real Int | Since: base-2.0.1 |
Defined in GHC.Real Methods toRational :: Int -> Rational # | |
| Real Word | Since: base-2.1 |
Defined in GHC.Real Methods toRational :: Word -> Rational # | |
| Real a => Real (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity Methods toRational :: Identity a -> Rational # | |
| Real a => Real (Down a) | Since: base-4.14.0.0 |
Defined in Data.Ord Methods toRational :: Down a -> Rational # | |
| Integral a => Real (Ratio a) | Since: base-2.0.1 |
Defined in GHC.Real Methods toRational :: Ratio a -> Rational # | |
| Real a => Real (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods toRational :: Const a b -> Rational # | |
class (Real a, Enum a) => Integral a where #
Integral numbers, supporting integer division.
The Haskell Report defines no laws for Integral. However, Integral
instances are customarily expected to define a Euclidean domain and have the
following properties for the div/mod and quot/rem pairs, given
suitable Euclidean functions f and g:
x=y * quot x y + rem x ywithrem x y=fromInteger 0org (rem x y)<g yx=y * div x y + mod x ywithmod x y=fromInteger 0orf (mod x y)<f y
An example of a suitable Euclidean function, for Integer's instance, is
abs.
Methods
quot :: a -> a -> a infixl 7 #
integer division truncated toward zero
integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
integer division truncated toward negative infinity
integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
conversion to Integer
Instances
| Integral IntPtr | |
Defined in Foreign.Ptr | |
| Integral WordPtr | |
Defined in Foreign.Ptr | |
| Integral Int16 | Since: base-2.1 |
| Integral Int32 | Since: base-2.1 |
| Integral Int64 | Since: base-2.1 |
| Integral Int8 | Since: base-2.1 |
| Integral Word16 | Since: base-2.1 |
| Integral Word32 | Since: base-2.1 |
| Integral Word64 | Since: base-2.1 |
| Integral Word8 | Since: base-2.1 |
| Integral Integer | Since: base-2.0.1 |
Defined in GHC.Real | |
| Integral Natural | Since: base-4.8.0.0 |
Defined in GHC.Real | |
| Integral Int | Since: base-2.0.1 |
| Integral Word | Since: base-2.1 |
| Integral a => Integral (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity Methods quot :: Identity a -> Identity a -> Identity a # rem :: Identity a -> Identity a -> Identity a # div :: Identity a -> Identity a -> Identity a # mod :: Identity a -> Identity a -> Identity a # quotRem :: Identity a -> Identity a -> (Identity a, Identity a) # divMod :: Identity a -> Identity a -> (Identity a, Identity a) # | |
| Integral a => Integral (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods quot :: Const a b -> Const a b -> Const a b # rem :: Const a b -> Const a b -> Const a b # div :: Const a b -> Const a b -> Const a b # mod :: Const a b -> Const a b -> Const a b # quotRem :: Const a b -> Const a b -> (Const a b, Const a b) # divMod :: Const a b -> Const a b -> (Const a b, Const a b) # | |
class Fractional a => Floating a where #
Trigonometric and hyperbolic functions and related functions.
The Haskell Report defines no laws for Floating. However, (, +)(
and *)exp are customarily expected to define an exponential field and have
the following properties:
exp (a + b)=exp a * exp bexp (fromInteger 0)=fromInteger 1
Minimal complete definition
pi, exp, log, sin, cos, asin, acos, atan, sinh, cosh, asinh, acosh, atanh
Instances
class Num a => Fractional a where #
Fractional numbers, supporting real division.
The Haskell Report defines no laws for Fractional. However, ( and
+)( are customarily expected to define a division ring and have the
following properties:*)
recipgives the multiplicative inversex * recip x=recip x * x=fromInteger 1
Note that it isn't customarily expected that a type instance of
Fractional implement a field. However, all instances in base do.
Minimal complete definition
fromRational, (recip | (/))
Methods
Fractional division.
Reciprocal fraction.
fromRational :: Rational -> a #
Conversion from a Rational (that is ).
A floating literal stands for an application of Ratio IntegerfromRational
to a value of type Rational, so such literals have type
(.Fractional a) => a
Instances
| RealFloat a => Fractional (Complex a) | Since: base-2.1 |
| Fractional a => Fractional (Identity a) | Since: base-4.9.0.0 |
| Fractional a => Fractional (Down a) | Since: base-4.14.0.0 |
| Integral a => Fractional (Ratio a) | Since: base-2.0.1 |
| Fractional a => Fractional (Const a b) | Since: base-4.9.0.0 |
class (Real a, Fractional a) => RealFrac a where #
Extracting components of fractions.
Minimal complete definition
Methods
properFraction :: Integral b => a -> (b, a) #
The function properFraction takes a real fractional number x
and returns a pair (n,f) such that x = n+f, and:
nis an integral number with the same sign asx; andfis a fraction with the same type and sign asx, and with absolute value less than1.
The default definitions of the ceiling, floor, truncate
and round functions are in terms of properFraction.
truncate :: Integral b => a -> b #
returns the integer nearest truncate xx between zero and x
round :: Integral b => a -> b #
returns the nearest integer to round xx;
the even integer if x is equidistant between two integers
ceiling :: Integral b => a -> b #
returns the least integer not less than ceiling xx
floor :: Integral b => a -> b #
returns the greatest integer not greater than floor xx
class (RealFrac a, Floating a) => RealFloat a where #
Efficient, machine-independent access to the components of a floating-point number.
Minimal complete definition
floatRadix, floatDigits, floatRange, decodeFloat, encodeFloat, isNaN, isInfinite, isDenormalized, isNegativeZero, isIEEE
Methods
floatRadix :: a -> Integer #
a constant function, returning the radix of the representation
(often 2)
floatDigits :: a -> Int #
a constant function, returning the number of digits of
floatRadix in the significand
floatRange :: a -> (Int, Int) #
a constant function, returning the lowest and highest values the exponent may assume
decodeFloat :: a -> (Integer, Int) #
The function decodeFloat applied to a real floating-point
number returns the significand expressed as an Integer and an
appropriately scaled exponent (an Int). If
yields decodeFloat x(m,n), then x is equal in value to m*b^^n, where b
is the floating-point radix, and furthermore, either m and n
are both zero or else b^(d-1) <= , where abs m < b^dd is
the value of .
In particular, floatDigits x. If the type
contains a negative zero, also decodeFloat 0 = (0,0).
The result of decodeFloat (-0.0) = (0,0) is unspecified if either of
decodeFloat x or isNaN x is isInfinite xTrue.
encodeFloat :: Integer -> Int -> a #
encodeFloat performs the inverse of decodeFloat in the
sense that for finite x with the exception of -0.0,
.
uncurry encodeFloat (decodeFloat x) = x is one of the two closest representable
floating-point numbers to encodeFloat m nm*b^^n (or ±Infinity if overflow
occurs); usually the closer, but if m contains too many bits,
the result may be rounded in the wrong direction.
exponent corresponds to the second component of decodeFloat.
and for finite nonzero exponent 0 = 0x,
.
If exponent x = snd (decodeFloat x) + floatDigits xx is a finite floating-point number, it is equal in value to
, where significand x * b ^^ exponent xb is the
floating-point radix.
The behaviour is unspecified on infinite or NaN values.
significand :: a -> a #
The first component of decodeFloat, scaled to lie in the open
interval (-1,1), either 0.0 or of absolute value >= 1/b,
where b is the floating-point radix.
The behaviour is unspecified on infinite or NaN values.
scaleFloat :: Int -> a -> a #
multiplies a floating-point number by an integer power of the radix
True if the argument is an IEEE "not-a-number" (NaN) value
isInfinite :: a -> Bool #
True if the argument is an IEEE infinity or negative infinity
isDenormalized :: a -> Bool #
True if the argument is too small to be represented in
normalized format
isNegativeZero :: a -> Bool #
True if the argument is an IEEE negative zero
True if the argument is an IEEE floating point number
a version of arctangent taking two real floating-point arguments.
For real floating x and y, computes the angle
(from the positive x-axis) of the vector from the origin to the
point atan2 y x(x,y). returns a value in the range [atan2 y x-pi,
pi]. It follows the Common Lisp semantics for the origin when
signed zeroes are supported. , with atan2 y 1y in a type
that is RealFloat, should return the same value as .
A default definition of atan yatan2 is provided, but implementors
can provide a more accurate implementation.
Instances
Numeric functions
gcd :: Integral a => a -> a -> a #
is the non-negative factor of both gcd x yx and y of which
every common factor of x and y is also a factor; for example
, gcd 4 2 = 2, gcd (-4) 6 = 2 = gcd 0 44. = gcd 0 00.
(That is, the common divisor that is "greatest" in the divisibility
preordering.)
Note: Since for signed fixed-width integer types, ,
the result may be negative if one of the arguments is abs minBound < 0 (and
necessarily is if the other is minBound0 or ) for such types.minBound
lcm :: Integral a => a -> a -> a #
is the smallest positive integer that both lcm x yx and y divide.
(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 #
raise a number to an integral power
fromIntegral :: (Integral a, Num b) => a -> b #
general coercion from integral types
realToFrac :: (Real a, Fractional b) => a -> b #
general coercion to fractional types
Monads and functors
(<*) :: (Applicative f, Consumable b) => f a %1 -> f b %1 -> f a infixl 4 Source #
Linearly typed replacement for the standard (<*) function.
Semigroups and monoids
module Data.Monoid.Linear
Miscellaneous functions
(.) :: forall {rep} b (c :: TYPE rep) a q m n. (b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c infixr 9 Source #
Beware: (.) is not compatible with the standard one because it is
higher-order and we don't have sufficient multiplicity polymorphism yet.
flip :: (a %p -> b %q -> c) %r -> b %q -> a %p -> c Source #
Replacement for the flip function with generalized multiplicities.
until :: (a -> Bool) -> (a -> a) -> a -> a #
yields the result of applying until p ff until p holds.
error :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => [Char] -> a #
error stops execution and displays an error message.
errorWithoutStackTrace :: forall (r :: RuntimeRep) (a :: TYPE r). [Char] -> a #
A variant of error that does not produce a stack trace.
Since: base-4.9.0.0
undefined :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => a #
seq :: a -> b %q -> b infixr 0 Source #
seq x y only forces x to head normal form, therefore is not guaranteed
to consume x when the resulting computation is consumed. Therefore, seq
cannot be linear in it's first argument.
List operations
module Data.List.Linear
Functions on strings
module Data.String
Converting to and from String
Conversion of values to readable Strings.
Derived instances of Show have the following properties, which
are compatible with derived instances of Read:
- The result of
showis a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - If the constructor is defined to be an infix operator, then
showsPrecwill produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
xis less thand(associativity is ignored). Thus, ifdis0then the result is never surrounded in parentheses; ifdis11it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
showwill produce the record-syntax form, with the fields given in the same order as the original declaration.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Show is equivalent to
instance (Show a) => Show (Tree a) where
showsPrec d (Leaf m) = showParen (d > app_prec) $
showString "Leaf " . showsPrec (app_prec+1) m
where app_prec = 10
showsPrec d (u :^: v) = showParen (d > up_prec) $
showsPrec (up_prec+1) u .
showString " :^: " .
showsPrec (up_prec+1) v
where up_prec = 5Note that right-associativity of :^: is ignored. For example,
produces the stringshow(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)".
Methods
Arguments
| :: Int | the operator precedence of the enclosing
context (a number from |
| -> a | the value to be converted to a |
| -> ShowS |
Convert a value to a readable String.
showsPrec should satisfy the law
showsPrec d x r ++ s == showsPrec d x (r ++ s)
Derived instances of Read and Show satisfy the following:
That is, readsPrec parses the string produced by
showsPrec, and delivers the value that showsPrec started with.
Instances
utility function converting a Char to a show function that
simply prepends the character unchanged.
showString :: String -> ShowS #
utility function converting a String to a show function that
simply prepends the string unchanged.
Parsing of Strings, producing values.
Derived instances of Read make the following assumptions, which
derived instances of Show obey:
- If the constructor is defined to be an infix operator, then the
derived
Readinstance will parse only infix applications of the constructor (not the prefix form). - Associativity is not used to reduce the occurrence of parentheses, although precedence may be.
- If the constructor is defined using record syntax, the derived
Readwill parse only the record-syntax form, and furthermore, the fields must be given in the same order as the original declaration. - The derived
Readinstance allows arbitrary Haskell whitespace between tokens of the input string. Extra parentheses are also allowed.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Read in Haskell 2010 is equivalent to
instance (Read a) => Read (Tree a) where
readsPrec d r = readParen (d > app_prec)
(\r -> [(Leaf m,t) |
("Leaf",s) <- lex r,
(m,t) <- readsPrec (app_prec+1) s]) r
++ readParen (d > up_prec)
(\r -> [(u:^:v,w) |
(u,s) <- readsPrec (up_prec+1) r,
(":^:",t) <- lex s,
(v,w) <- readsPrec (up_prec+1) t]) r
where app_prec = 10
up_prec = 5Note that right-associativity of :^: is unused.
The derived instance in GHC is equivalent to
instance (Read a) => Read (Tree a) where
readPrec = parens $ (prec app_prec $ do
Ident "Leaf" <- lexP
m <- step readPrec
return (Leaf m))
+++ (prec up_prec $ do
u <- step readPrec
Symbol ":^:" <- lexP
v <- step readPrec
return (u :^: v))
where app_prec = 10
up_prec = 5
readListPrec = readListPrecDefaultWhy do both readsPrec and readPrec exist, and why does GHC opt to
implement readPrec in derived Read instances instead of readsPrec?
The reason is that readsPrec is based on the ReadS type, and although
ReadS is mentioned in the Haskell 2010 Report, it is not a very efficient
parser data structure.
readPrec, on the other hand, is based on a much more efficient ReadPrec
datatype (a.k.a "new-style parsers"), but its definition relies on the use
of the RankNTypes language extension. Therefore, readPrec (and its
cousin, readListPrec) are marked as GHC-only. Nevertheless, it is
recommended to use readPrec instead of readsPrec whenever possible
for the efficiency improvements it brings.
As mentioned above, derived Read instances in GHC will implement
readPrec instead of readsPrec. The default implementations of
readsPrec (and its cousin, readList) will simply use readPrec under
the hood. If you are writing a Read instance by hand, it is recommended
to write it like so:
instanceReadT wherereadPrec= ...readListPrec=readListPrecDefault
Methods
Arguments
| :: Int | the operator precedence of the enclosing
context (a number from |
| -> ReadS a |
attempts to parse a value from the front of the string, returning a list of (parsed value, remaining string) pairs. If there is no successful parse, the returned list is empty.
Derived instances of Read and Show satisfy the following:
That is, readsPrec parses the string produced by
showsPrec, and delivers the value that
showsPrec started with.
Instances
| Read All | Since: base-2.1 |
| Read Any | Since: base-2.1 |
| Read Version | Since: base-2.1 |
| Read Void | Reading a Since: base-4.8.0.0 |
| Read IntPtr | |
| Read WordPtr | |
| Read Associativity | Since: base-4.6.0.0 |
Defined in GHC.Generics Methods readsPrec :: Int -> ReadS Associativity # readList :: ReadS [Associativity] # | |
| Read DecidedStrictness | Since: base-4.9.0.0 |
Defined in GHC.Generics Methods readsPrec :: Int -> ReadS DecidedStrictness # readList :: ReadS [DecidedStrictness] # | |
| Read Fixity | Since: base-4.6.0.0 |
| Read SourceStrictness | Since: base-4.9.0.0 |
Defined in GHC.Generics Methods readsPrec :: Int -> ReadS SourceStrictness # readList :: ReadS [SourceStrictness] # | |
| Read SourceUnpackedness | Since: base-4.9.0.0 |
Defined in GHC.Generics Methods readsPrec :: Int -> ReadS SourceUnpackedness # readList :: ReadS [SourceUnpackedness] # | |
| Read SeekMode | Since: base-4.2.0.0 |
| Read ExitCode | |
| Read BufferMode | Since: base-4.2.0.0 |
Defined in GHC.IO.Handle.Types Methods readsPrec :: Int -> ReadS BufferMode # readList :: ReadS [BufferMode] # readPrec :: ReadPrec BufferMode # readListPrec :: ReadPrec [BufferMode] # | |
| Read Newline | Since: base-4.3.0.0 |
| Read NewlineMode | Since: base-4.3.0.0 |
Defined in GHC.IO.Handle.Types Methods readsPrec :: Int -> ReadS NewlineMode # readList :: ReadS [NewlineMode] # readPrec :: ReadPrec NewlineMode # readListPrec :: ReadPrec [NewlineMode] # | |
| Read IOMode | Since: base-4.2.0.0 |
| Read Int16 | Since: base-2.1 |
| Read Int32 | Since: base-2.1 |
| Read Int64 | Since: base-2.1 |
| Read Int8 | Since: base-2.1 |
| Read GCDetails | Since: base-4.10.0.0 |
| Read RTSStats | Since: base-4.10.0.0 |
| Read SomeChar | |
| Read SomeSymbol | Since: base-4.7.0.0 |
Defined in GHC.TypeLits Methods readsPrec :: Int -> ReadS SomeSymbol # readList :: ReadS [SomeSymbol] # readPrec :: ReadPrec SomeSymbol # readListPrec :: ReadPrec [SomeSymbol] # | |
| Read SomeNat | Since: base-4.7.0.0 |
| Read GeneralCategory | Since: base-2.1 |
Defined in GHC.Read Methods readsPrec :: Int -> ReadS GeneralCategory # readList :: ReadS [GeneralCategory] # | |
| Read Word16 | Since: base-2.1 |
| Read Word32 | Since: base-2.1 |
| Read Word64 | Since: base-2.1 |
| Read Word8 | Since: base-2.1 |
| Read Lexeme | Since: base-2.1 |
| Read ByteString | |
Defined in Data.ByteString.Internal Methods readsPrec :: Int -> ReadS ByteString # readList :: ReadS [ByteString] # readPrec :: ReadPrec ByteString # readListPrec :: ReadPrec [ByteString] # | |
| Read ByteString | |
Defined in Data.ByteString.Lazy.Internal Methods readsPrec :: Int -> ReadS ByteString # readList :: ReadS [ByteString] # readPrec :: ReadPrec ByteString # readListPrec :: ReadPrec [ByteString] # | |
| Read ShortByteString | |
Defined in Data.ByteString.Short.Internal Methods readsPrec :: Int -> ReadS ShortByteString # readList :: ReadS [ShortByteString] # | |
| Read IntSet | |
| Read Ordering | Since: base-2.1 |
| Read DatatypeVariant | |
Defined in Language.Haskell.TH.Datatype Methods readsPrec :: Int -> ReadS DatatypeVariant # readList :: ReadS [DatatypeVariant] # | |
| Read Integer | Since: base-2.1 |
| Read Natural | Since: base-4.8.0.0 |
| Read () | Since: base-2.1 |
| Read Bool | Since: base-2.1 |
| Read Char | Since: base-2.1 |
| Read Double | Since: base-2.1 |
| Read Float | Since: base-2.1 |
| Read Int | Since: base-2.1 |
| Read Word | Since: base-4.5.0.0 |
| Read a => Read (ZipList a) | Since: base-4.7.0.0 |
| Read a => Read (Complex a) | Since: base-2.1 |
| Read a => Read (Identity a) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| Read a => Read (First a) | Since: base-2.1 |
| Read a => Read (Last a) | Since: base-2.1 |
| Read a => Read (Down a) | This instance would be equivalent to the derived instances of the
Since: base-4.7.0.0 |
| Read a => Read (First a) | Since: base-4.9.0.0 |
| Read a => Read (Last a) | Since: base-4.9.0.0 |
| Read a => Read (Max a) | Since: base-4.9.0.0 |
| Read a => Read (Min a) | Since: base-4.9.0.0 |
| Read m => Read (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods readsPrec :: Int -> ReadS (WrappedMonoid m) # readList :: ReadS [WrappedMonoid m] # readPrec :: ReadPrec (WrappedMonoid m) # readListPrec :: ReadPrec [WrappedMonoid m] # | |
| Read a => Read (Dual a) | Since: base-2.1 |
| Read a => Read (Product a) | Since: base-2.1 |
| Read a => Read (Sum a) | Since: base-2.1 |
| Read p => Read (Par1 p) | Since: base-4.7.0.0 |
| (Integral a, Read a) => Read (Ratio a) | Since: base-2.1 |
| Read e => Read (IntMap e) | |
| Read a => Read (Seq a) | |
| Read a => Read (ViewL a) | |
| Read a => Read (ViewR a) | |
| (Read a, Ord a) => Read (Set a) | |
| Read a => Read (Tree a) | |
| Read a => Read (Array a) | |
| Read a => Read (Vector a) | |
| Read a => Read (NonEmpty a) | Since: base-4.11.0.0 |
| Read a => Read (Maybe a) | Since: base-2.1 |
| Read a => Read (a) | Since: base-4.15 |
| Read a => Read [a] | Since: base-2.1 |
| (Read a, Read b) => Read (Either a b) | Since: base-3.0 |
| Read (Proxy t) | Since: base-4.7.0.0 |
| (Read a, Read b) => Read (Arg a b) | Since: base-4.9.0.0 |
| (Ix a, Read a, Read b) => Read (Array a b) | Since: base-2.1 |
| Read (U1 p) | Since: base-4.9.0.0 |
| Read (V1 p) | Since: base-4.9.0.0 |
| (Ord k, Read k, Read e) => Read (Map k e) | |
| (Read1 m, Read a) => Read (ListT m a) | |
| (Read1 m, Read a) => Read (MaybeT m a) | |
| (Read a, Read b) => Read (a, b) | Since: base-2.1 |
| Read a => Read (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| Read (f a) => Read (Ap f a) | Since: base-4.12.0.0 |
| Read (f a) => Read (Alt f a) | Since: base-4.8.0.0 |
| a ~ b => Read (a :~: b) | Since: base-4.7.0.0 |
| Read (f p) => Read (Rec1 f p) | Since: base-4.7.0.0 |
| (Read e, Read1 m, Read a) => Read (ErrorT e m a) | |
| (Read e, Read1 m, Read a) => Read (ExceptT e m a) | |
| (Read1 f, Read a) => Read (IdentityT f a) | |
| (Read w, Read1 m, Read a) => Read (WriterT w m a) | |
| (Read w, Read1 m, Read a) => Read (WriterT w m a) | |
| (Read a, Read b, Read c) => Read (a, b, c) | Since: base-2.1 |
| (Read1 f, Read1 g, Read a) => Read (Product f g a) | Since: base-4.9.0.0 |
| (Read1 f, Read1 g, Read a) => Read (Sum f g a) | Since: base-4.9.0.0 |
| a ~~ b => Read (a :~~: b) | Since: base-4.10.0.0 |
| (Read (f p), Read (g p)) => Read ((f :*: g) p) | Since: base-4.7.0.0 |
| (Read (f p), Read (g p)) => Read ((f :+: g) p) | Since: base-4.7.0.0 |
| Read c => Read (K1 i c p) | Since: base-4.7.0.0 |
| Read (f a) => Read (MP1 m f a) | |
| (Read a, Read b, Read c, Read d) => Read (a, b, c, d) | Since: base-2.1 |
| (Read1 f, Read1 g, Read a) => Read (Compose f g a) | Since: base-4.9.0.0 |
| Read (f (g p)) => Read ((f :.: g) p) | Since: base-4.7.0.0 |
| Read (f p) => Read (M1 i c f p) | Since: base-4.7.0.0 |
| Read (f (g x)) => Read ((f :.: g) x) | |
| (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) => Read (a, b, c, d, e, f, g, h) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i) => Read (a, b, c, d, e, f, g, h, i) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j) => Read (a, b, c, d, e, f, g, h, i, j) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k) => Read (a, b, c, d, e, f, g, h, i, j, k) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l) => Read (a, b, c, d, e, f, g, h, i, j, k, l) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n, Read o) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | Since: base-2.1 |
Defined in GHC.Read | |
read :: Read a => String -> a #
The read function reads input from a string, which must be
completely consumed by the input process. read fails with an error if the
parse is unsuccessful, and it is therefore discouraged from being used in
real applications. Use readMaybe or readEither for safe alternatives.
>>>read "123" :: Int123
>>>read "hello" :: Int*** Exception: Prelude.read: no parse
The lex function reads a single lexeme from the input, discarding
initial white space, and returning the characters that constitute the
lexeme. If the input string contains only white space, lex returns a
single successful `lexeme' consisting of the empty string. (Thus
.) If there is no legal lexeme at the
beginning of the input string, lex "" = [("","")]lex fails (i.e. returns []).
This lexer is not completely faithful to the Haskell lexical syntax in the following respects:
- Qualified names are not handled properly
- Octal and hexadecimal numerics are not recognized as a single token
- Comments are not treated properly
Basic input and output
A value of type is a computation which, when performed,
does some I/O before returning a value of type IO aa.
There is really only one way to "perform" an I/O action: bind it to
Main.main in your program. When your program is run, the I/O will
be performed. It isn't possible to perform I/O from an arbitrary
function, unless that function is itself in the IO monad and called
at some point, directly or indirectly, from Main.main.
IO is a monad, so IO actions can be combined using either the do-notation
or the >> and >>= operations from the Monad
class.
Instances
print :: Show a => a -> IO () #
The print function outputs a value of any printable type to the
standard output device.
Printable types are those that are instances of class Show; print
converts values to strings for output using the show operation and
adds a newline.
For example, a program to print the first 20 integers and their powers of 2 could be written as:
main = print ([(n, 2^n) | n <- [0..19]])
getContents :: IO String #
The getContents operation returns all user input as a single string,
which is read lazily as it is needed
(same as hGetContents stdin).
interact :: (String -> String) -> IO () #
The interact function takes a function of type String->String
as its argument. The entire input from the standard input device is
passed to this function as its argument, and the resulting string is
output on the standard output device.
Files
File and directory names are values of type String, whose precise
meaning is operating system dependent. Files can be opened, yielding a
handle which can then be used to operate on the contents of that file.
readFile :: FilePath -> IO String #
The readFile function reads a file and
returns the contents of the file as a string.
The file is read lazily, on demand, as with getContents.
writeFile :: FilePath -> String -> IO () #
The computation writeFile file str function writes the string str,
to the file file.
appendFile :: FilePath -> String -> IO () #
The computation appendFile file str function appends the string str,
to the file file.
Note that writeFile and appendFile write a literal string
to a file. To write a value of any printable type, as with print,
use the show function to convert the value to a string first.
main = appendFile "squares" (show [(x,x*x) | x <- [0,0.1..2]])
Using Ur values in linear code
Ur a represents unrestricted values of type a in a linear
context. The key idea is that because the contructor holds a with a
regular arrow, a function that uses Ur a linearly can use a
however it likes.
someLinear :: Ur a %1-> (a,a) someLinear (Ur a) = (a,a)
Instances
Get an a out of an Ur a. If you call this function on a
linearly bound Ur a, then the a you get out has to be used
linearly, for example:
restricted :: Ur a %1-> b
restricted x = f (unur x)
where
-- f __must__ be linear
f :: a %1-> b
f x = ...Doing non-linear operations inside linear functions
class Consumable a where Source #
Instances
class Consumable a => Dupable a where Source #
The laws of Dupable are dual to those of Monoid:
- 1.
first consume (dup2 a) ≃ a ≃ second consume (dup2 a)(dup2neutrality) - 2.
first dup2 (dup2 a) ≃ (second dup2 (dup2 a))(dup2associativity)
where the (≃) sign represents equality up to type isomorphism.
- 3.
dup2 = Replicator.elim (,) . dupR(coherence betweendup2anddupR) - 4.
consume = Replicator.elim () . dupR(coherence betweenconsumeanddupR) - 5.
Replicator.extract . dupR = id(dupRidentity) - 6.
dupR . dupR = (Replicator.map dupR) . dupR(dupRinterchange)
(Laws 1-2 and 5-6 are equivalent)
Implementation of Dupable for Movable types should
be done with deriving via .AsMovable
Implementation of Dupable for other types can be done with
deriving via . Note that at present this mechanism
can have performance problems for recursive parameterized types.
Specifically, the methods will not specialize to underlying GenericallyDupable
instances. See this GHC issue.
Methods
dupR :: a %1 -> Replicator a Source #
Creates a Replicator for the given a.
You usually want to define this method using Replicator's
Applicative instance. For instance, here is an
implementation of :Dupable [a]
instance Dupable a => Dupable [a] where dupR [] = pure [] dupR (a : as) = (:) <$> dupR a <*> dupR as
dup2 :: a %1 -> (a, a) Source #
Creates two as from a , in a linear fashion.Dupable a
Instances
class Dupable a => Movable a where Source #
Use to represent a type which can be used many times even
when given linearly. Simple data types such as Movable aBool or [] are Movable.
Though, bear in mind that this typically induces a deep copy of the value.
Formally, is the class of
coalgebras of the
Movable aUr comonad. That is
unur (move x) = x
move @(Ur a) (move @a x) = fmap (move @a) $ move @a x
Additionally, a Movable instance must be compatible with its Dupable parent instance. That is:
case move x of {Ur _ -> ()} = consume xcase move x of {Ur x -> (x, x)} = dup2 x
Instances
lseq :: Consumable a => a %1 -> b %1 -> b infixr 0 Source #
Consume the first argument and return the second argument.
This is like seq but the first argument is restricted to be Consumable.