| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Universe
Description
The idea is to create a world of Haskell types, called a Universe. Then to
define a 'class' whose methods are only applicable to that set of types. We define
a closed set by defining an indexed type constructor Rep. If (Singleton Rep), then it must
be that every value of type (Rep t) has exactly 0 or 1 inhabitants. (Rep t) has exactly
1 inhabitant if t is in the universe, and 0 inhabitants if it is not in the universe.
A closely related class is (Indexed s t). We would like a total ordering on (t i) and (t j),
where the indices, i and j, are different. We do this by ensuring every value of type (t i)
has a unique Shape, and that the type Shape has a total order. Every closed singleton can
be totally ordered this way. Other indexed types are used to make well-type terms. I.e.
Indexed s t => Exp t, denotes a Haskell data type Exp, related to the type t.
Note, unlike singletons, there may not be a unique value of type (Exp t), but there may be
a unique Shape for every value.
Synopsis
- class Shaped (t ∷ k → Type) (rep ∷ Type → Type) where
- class Singleton (t ∷ k → Type) where
- class Singleton rep ⇒ Universe (rep ∷ k → Type) (t ∷ k) where
- repOf ∷ rep t
- data Any (t ∷ k → Type) where
- data Some (t ∷ k → Type) where
- data Dyn (rep ∷ Type → Type) where
- data Shape (rep ∷ Type → Type) where
- type Eql (x ∷ k) (y ∷ k) = x :~: y
- data (a ∷ k) :~: (b ∷ k) where
- data TypeRep (a ∷ k)
- compareByShape ∷ ∀ (rep ∷ Type → Type) t i j. Shaped t rep ⇒ t i → t j → Ordering
Documentation
class Shaped (t ∷ k → Type) (rep ∷ Type → Type) where Source #
For some indexed types, we can assign a unique Shape to each type,
using: shape :: t i -> Shape s (where s is some Singleton type)
the class (Shaped t s) means we can assign a unique Shape to each
value of type (t i). Not quite as strong as having a unique inhabitant.
Every closed singleton type can be shaped, and many other indexed types
can be shaped as well.
class Singleton (t ∷ k → Type) where Source #
Given (Singleton T), a value of type (T i) has exactly 0 or 1 inhabitants,
so we can compare the structure of the type to get proofs that the indexes (i and j)
are the same type, using testEql, at runtime. cmpIndex, it is like compare
except we can have two different indexes (a and b).
class Singleton rep ⇒ Universe (rep ∷ k → Type) (t ∷ k) where Source #
A minimal class of operations defined on the universe described by rep .
Feel free to make your own Universe classes with additional methods
data Some (t ∷ k → Type) where Source #
Hide the index for a singleton type t
data Shape (rep ∷ Type → Type) where Source #
Constructors
| Nullary ∷ ∀ (rep ∷ Type → Type). Int → Shape rep | |
| Nary ∷ ∀ (rep ∷ Type → Type). Int → [Shape rep] → Shape rep | |
| Esc ∷ ∀ (rep ∷ Type → Type) t. (Singleton rep, Ord t) ⇒ rep t → t → Shape rep |
type Eql (x ∷ k) (y ∷ k) = x :~: y Source #
Type synonym, so we can use ( :~: ) without TypeOperators
data (a ∷ k) :~: (b ∷ k) where infix 4 #
Propositional equality. If a :~: b is inhabited by some terminating
value, then the type a is the same as the type b. To use this equality
in practice, pattern-match on the a :~: b to get out the Refl constructor;
in the body of the pattern-match, the compiler knows that a ~ b.
Since: base-4.7.0.0
Instances
| TestEquality ((:~:) a ∷ k → Type) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Type.Equality | |
| NFData2 ((:~:) ∷ Type → Type → Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| NFData1 ((:~:) a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| NFData (a :~: b) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| a ~ b ⇒ Bounded (a :~: b) | Since: base-4.7.0.0 |
| a ~ b ⇒ Enum (a :~: b) | Since: base-4.7.0.0 |
| a ~ b ⇒ Read (a :~: b) | Since: base-4.7.0.0 |
| Show (a :~: b) | Since: base-4.7.0.0 |
| Eq (a :~: b) | Since: base-4.7.0.0 |
| Ord (a :~: b) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Type.Equality | |
TypeRep is a concrete representation of a (monomorphic) type.
TypeRep supports reasonably efficient equality.
See Note [Grand plan for Typeable] in GHC.Tc.Instance.Typeable
Instances
| Singleton (TypeRep ∷ k → Type) Source # | |
| TestEquality (TypeRep ∷ k → Type) | |
Defined in GHC.Internal.Data.Typeable.Internal | |
| NFData (TypeRep a) | Since: deepseq-1.4.8.0 |
Defined in Control.DeepSeq | |
| Show (TypeRep a) | |
| Eq (TypeRep a) | Since: base-2.1 |
| Ord (TypeRep a) | Since: base-4.4.0.0 |
Defined in GHC.Internal.Data.Typeable.Internal | |
| Hashable (TypeRep a) | |