:: a -> () -package:ghc-prim

Reduce to weak head normal form Equivalent to \x -> seq x (). Useful for defining NFData for types for which NF=WHNF holds.
data T = C1 | C2 | C3
instance NFData T where rnf = rwhnf
Coerce a value from one type to another, bypassing the type-checker. There are several legitimate ways to use unsafeCoerce:
  1. To coerce e.g. Int to HValue, put it in a list of HValue, and then later coerce it back to Int before using it.
  2. To produce e.g. (a+b) :~: (b+a) from unsafeCoerce Refl. Here the two sides really are the same type -- so nothing unsafe is happening -- but GHC is not clever enough to see it.
  3. In Data.Typeable we have
eqTypeRep :: forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep a b
| sameTypeRep a b = Just (unsafeCoerce HRefl)
| otherwise       = Nothing

Here again, the unsafeCoerce HRefl is safe, because the two types really are the same -- but the proof of that relies on the complex, trusted implementation of Typeable.
  1. The "reflection trick", which takes advantage of the fact that in class C a where { op :: ty }, we can safely coerce between C a and ty (which have different kinds!) because it's really just a newtype. Note: there is no guarantee, at all that this behavior will be supported into perpetuity.
For safe zero-cost coercions you can instead use the coerce function from Data.Coerce.
Highly, terribly dangerous coercion from one representation type to another. Misuse of this function can invite the garbage collector to trounce upon your data and then laugh in your face. You don't want this function. Really.
Highly, terribly dangerous coercion from one representation type to another. Misuse of this function can invite the garbage collector to trounce upon your data and then laugh in your face. You don't want this function. Really.
Coerce a value from one type to another, bypassing the type-checker. There are several legitimate ways to use unsafeCoerce:
  1. To coerce e.g. Int to HValue, put it in a list of HValue, and then later coerce it back to Int before using it.
  2. To produce e.g. (a+b) :~: (b+a) from unsafeCoerce Refl. Here the two sides really are the same type -- so nothing unsafe is happening -- but GHC is not clever enough to see it.
  3. In Data.Typeable we have
eqTypeRep :: forall k1 k2 (a :: k1) (b :: k2).
TypeRep a -> TypeRep b -> Maybe (a :~~: b)
eqTypeRep a b
| sameTypeRep a b = Just (unsafeCoerce HRefl)
| otherwise       = Nothing

Here again, the unsafeCoerce HRefl is safe, because the two types really are the same -- but the proof of that relies on the complex, trusted implementation of Typeable.
  1. The "reflection trick", which takes advantage of the fact that in class C a where { op :: ty }, we can safely coerce between C a and ty (which have different kinds!) because it's really just a newtype. Note: there is no guarantee, at all that this behavior will be supported into perpetuity.
toFields provides a convenient typeclass wrapper around the Field_ creation functions in Opaleye.SqlTypes. Besides convenience it doesn't provide any additional functionality. It can be used with functions like runInsert to insert custom Haskell types into the database. The following is an example of a function for inserting custom types.
customInsert
:: ( Default ToFields haskells fields )
=> Connection
-> Table fields fields'
-> [haskells]
-> IO Int64
customInsert conn table haskells = runInsert_ conn Insert {
iTable      = table
, iRows       = map toFields haskells
, iReturning  = rCount
, iOnConflict = Nothing
}
In order to use this function with your custom types, you need to define an instance of Default ToFields for your custom types.
Version of toFields with better type inference
Lift r to the answer type, similar to return. This return function aims to be used as the last statement of a do block. When return is present in a nested do block for when or unless, if the r' is not (), it will create a Cont that performs early return, skipping the rest statements of the outer do notation.

Examples

>>> :set -XTypeOperators

>>> :set -XRebindableSyntax

>>> import Prelude hiding ((>>), (>>=), return, fail)

>>> import Control.Dsl

>>> import Control.Dsl.Return

>>> import Control.Dsl.Yield

>>> import Control.Dsl.Cont

>>> import Control.Dsl.Empty
>>> :{
earlyGenerator :: Bool -> Cont [String] Integer
earlyGenerator earlyReturn = do
Yield "inside earlyGenerator"
when earlyReturn $ do
Yield "early return"
return 1
Yield "normal return"
return 0
:}
>>> :{
earlyGeneratorTest :: [String]
earlyGeneratorTest = do
Yield "before earlyGenerator"
i <- earlyGenerator True
Yield "after earlyGenerator"
Yield $ "the return value of earlyGenerator is " ++ show i
empty
:}
>>> earlyGeneratorTest
["before earlyGenerator","inside earlyGenerator","early return","after earlyGenerator","the return value of earlyGenerator is 1"]
Compute the number of segments of anything measured by SegMeasure (e.g. SegMeasure itself, Segment, SegTree, Trails...)
Euclidean norm of a vector.
A utility, which uses the Show instance to produce a value that is isomorphic to String. It lets you generalize over the functions like the following:
showAsText :: Show a => a -> Text
showAsText = showAs @Text
showAsBuilder :: Show a => a -> Builder
showAsBuilder = showAs @Builder
\x -> ceiling (-x) == negate (floor (x::Double) :: Integer)
\x -> ceiling (-x) == negate (floor (x::Rational) :: Integer)
\x -> ceiling (-x) == negate (floor (x::Double) :: Integer)
\x -> ceiling (-x) == negate (floor (x::Rational) :: Integer)