1 -----------------------------------------------------------------------------
4 -- Copyright : (c) The University of Glasgow 2001
5 -- License : BSD-style (see the file libraries/base/LICENSE)
7 -- Maintainer : libraries@haskell.org
8 -- Stability : experimental
9 -- Portability : portable
11 -- This module provides a style of encoding types as values and using
12 -- them. This style is seens as an alternative to the pragmatic style
13 -- used in Data.Typeable and elsewhere, i.e., simply use an undefined
14 -- to denote a type argument. This pragmatic style suffers from lack
15 -- of robustness: one fells tempted to pattern match on undefineds.
17 -----------------------------------------------------------------------------
23 TypeVal, -- view type "a" as "a -> ()"
24 typeVal, -- :: TypeVal a
25 typeValOf, -- :: a -> TypeVal a
26 undefinedType, -- :: TypeVal a -> a
27 withType, -- :: a -> TypeVal a -> a
28 argType, -- :: (a -> b) -> TypeVal a
29 resType, -- :: (a -> b) -> TypeVal b
30 TypeFun -- functions on types
35 -------------------------------------------------------------
39 -------------------------------------------------------------
42 -- Type as values to stipulate use of undefineds
43 type TypeVal a = a -> ()
46 --- The value that denotes a type
51 -- Map a value to its type
52 typeValOf :: a -> TypeVal a
56 -- Stipulate this idiom!
57 undefinedType :: TypeVal a -> a
58 undefinedType _ = undefined
62 withType :: a -> TypeVal a -> a
66 -- The argument type of a function
67 argType :: (a -> b) -> TypeVal a
71 -- The result type of a function
72 resType :: (a -> b) -> TypeVal b
77 -- i.e., functions mapping types to values
79 type TypeFun a r = TypeVal a -> r