| base-3.0.1.0: Basic libraries | Source code | Contents | Index

Data.Dynamic |

Portability | portable
Stability | experimental
Maintainer | libraries@haskell.org

Contents

The `Dynamic` type
Converting to and from `Dynamic`
Applying functions of dynamic type

Description
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.
Synopsis

module Data.Typeable
data Dynamic
toDyn :: Typeable a => a -> Dynamic
fromDyn :: Typeable a => Dynamic -> a -> a
fromDynamic :: Typeable a => Dynamic -> Maybe a
dynApply :: Dynamic -> Dynamic -> Maybe Dynamic
dynApp :: Dynamic -> Dynamic -> Dynamic
dynTypeRep :: Dynamic -> TypeRep

Documentation
module Data.Typeable
The `Dynamic` type

data Dynamic | Source

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`).

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

Instances

Show Dynamic
Typeable Dynamic

Converting to and from `Dynamic`

toDyn :: Typeable a => a -> Dynamic | Source

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)

fromDyn | Source

:: Typeable a |
=> Dynamic | the dynamically-typed object
-> a | a default value
-> 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`.

fromDynamic | Source

:: Typeable a |
=> Dynamic | the dynamically-typed object
-> Maybe a | returns: ``Just` a`, if the dynamically-typed object has the correct type (and `a` is its value), or `Nothing` otherwise.
Converts a `Dynamic` object back into an ordinary Haskell value of the correct type. See also `fromDyn`.

Applying functions of dynamic type

dynApply :: Dynamic -> Dynamic -> Maybe Dynamic | Source

dynApp :: Dynamic -> Dynamic -> Dynamic | Source

dynTypeRep :: Dynamic -> TypeRep | Source

Produced by Haddock version 0.8