HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Moduleghc-internal-10.0.0Haskell2010

GHC.Internal.Data.Dynamic

The Dynamic interface provides basic support for dynamic types.

Operations for injecting values of arbitrary type into a dynamically typed value, Dynamic, are provided, together with operations for converting dynamic values into a concrete (monomorphic) type.

Contents
  1. The Dynamic type
  2. Converting to and from Dynamic
  3. Applying functions of dynamic type
  4. Convenience re-exports
Synopsis

The Dynamic type

datadata Dynamic where

A value of type Dynamic is an object encapsulated together with its type.

A Dynamic may only represent a monomorphic value; an attempt to create a value of type Dynamic from a polymorphically-typed expression will result in an ambiguity error (see toDyn).

Showing a value of type Dynamic returns a pretty-printed representation of the object's type; useful for debugging.

Constructors

Instances2Show, Exception
  • Show DynamicDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Dynamic
  • Exception DynamicDefined in ghc-internal-10.0.0 · GHC.Internal.Data.Dynamic

Converting to and from Dynamic

valuetoDyn :: Typeable a => a -> Dynamic

Converts an arbitrary value into an object of type Dynamic.

The type of the object must be an instance of Typeable, which ensures that only monomorphically-typed objects may be converted to Dynamic. To convert a polymorphic object into Dynamic, give it a monomorphic type signature. For example:

   toDyn (id :: Int -> Int)
valuefromDyn
  1. :: Typeable a
  2. => Dynamic

    the dynamically-typed object

  3. -> a

    a default value

  4. -> a

    returns: the value of the first argument, if it has the correct type, otherwise the value of the second argument.

Converts a Dynamic object back into an ordinary Haskell value of the correct type. See also fromDynamic.

Applying functions of dynamic type

Convenience re-exports

classclass Typeable (a :: k) where

The class Typeable allows a concrete representation of a type to be calculated.