| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Data.Units.Core
Synopsis
- module Data.Units.Core.System
- module Data.Units.Core.Convert
- module Data.Units.Core.Arithmetic
- module Data.Units.Core.Prefix
- module Data.Units.Core.TH
- coerce :: Coercible a b => a -> b
- module Data.Type.Int
- data ErrorMessage
Core modules
module Data.Units.Core.System
module Data.Units.Core.Convert
module Data.Units.Core.Arithmetic
module Data.Units.Core.Prefix
module Data.Units.Core.TH
Re-exported for Template Haskell to work out of the box
coerce :: Coercible a b => a -> b #
The function coerce allows you to safely convert between values of
types that have the same representation with no run-time overhead. In the
simplest case you can use it instead of a newtype constructor, to go from
the newtype's concrete type to the abstract type. But it also works in
more complicated settings, e.g. converting a list of newtypes to a list of
concrete types.
When used in conversions involving a newtype wrapper, make sure the newtype constructor is in scope.
This function is representation-polymorphic, but the
RuntimeRep type argument is marked as Inferred, meaning
that it is not available for visible type application. This means
the typechecker will accept .coerce @Int @Age 42
Examples
>>>newtype TTL = TTL Int deriving (Eq, Ord, Show)>>>newtype Age = Age Int deriving (Eq, Ord, Show)>>>coerce (Age 42) :: TTLTTL 42>>>coerce (+ (1 :: Int)) (Age 42) :: TTLTTL 43>>>coerce (map (+ (1 :: Int))) [Age 42, Age 24] :: [TTL][TTL 43,TTL 25]
Type level integers
module Data.Type.Int
Re-exported from GHC.TypeError
data ErrorMessage #
A description of a custom type error.
Constructors
| Text Symbol | Show the text as is. |
| ShowType t | Pretty print the type.
|
| ErrorMessage :<>: ErrorMessage infixl 6 | Put two pieces of error message next to each other. |
| ErrorMessage :$$: ErrorMessage infixl 5 | Stack two pieces of error message on top of each other. |