Copyright | Copyright (c) 2016 the Hakaru team |
---|---|
License | BSD3 |
Maintainer | wren@community.haskell.org |
Stability | experimental |
Portability | GHC-only |
Safe Haskell | None |
Language | Haskell2010 |
A collection of classes generalizing standard classes in order to support indexed types.
TODO: DeriveDataTypeable for all our newtypes?
- class Show1 a where
- shows1 :: Show1 a => a i -> ShowS
- showList1 :: Show1 a => [a i] -> ShowS
- class Show2 a where
- shows2 :: Show2 a => a i j -> ShowS
- showList2 :: Show2 a => [a i j] -> ShowS
- showListWith :: (a -> ShowS) -> [a] -> ShowS
- showTuple :: [ShowS] -> ShowS
- showParen_0 :: Show a => Int -> String -> a -> ShowS
- showParen_1 :: Show1 a => Int -> String -> a i -> ShowS
- showParen_2 :: Show2 a => Int -> String -> a i j -> ShowS
- showParen_01 :: (Show b, Show1 a) => Int -> String -> b -> a i -> ShowS
- showParen_02 :: (Show b, Show2 a) => Int -> String -> b -> a i j -> ShowS
- showParen_11 :: (Show1 a, Show1 b) => Int -> String -> a i -> b j -> ShowS
- showParen_12 :: (Show1 a, Show2 b) => Int -> String -> a i -> b j l -> ShowS
- showParen_22 :: (Show2 a, Show2 b) => Int -> String -> a i1 j1 -> b i2 j2 -> ShowS
- showParen_010 :: (Show a, Show1 b, Show c) => Int -> String -> a -> b i -> c -> ShowS
- showParen_011 :: (Show a, Show1 b, Show1 c) => Int -> String -> a -> b i -> c j -> ShowS
- showParen_111 :: (Show1 a, Show1 b, Show1 c) => Int -> String -> a i -> b j -> c k -> ShowS
- class Eq1 a where
- class Eq2 a where
- data TypeEq :: k -> k -> * where
- symmetry :: TypeEq a b -> TypeEq b a
- transitivity :: TypeEq a b -> TypeEq b c -> TypeEq a c
- congruence :: TypeEq a b -> TypeEq (f a) (f b)
- class Eq1 a => JmEq1 a where
- class Eq2 a => JmEq2 a where
- class Functor11 f where
- newtype Fix11 f i = Fix11 {}
- cata11 :: forall f a j. Functor11 f => (forall i. f a i -> a i) -> Fix11 f j -> a j
- ana11 :: forall f a j. Functor11 f => (forall i. a i -> f a i) -> a j -> Fix11 f j
- hylo11 :: forall f a b j. Functor11 f => (forall i. a i -> f a i) -> (forall i. f b i -> b i) -> a j -> b j
- class Functor12 f where
- class Functor21 f where
- class Functor22 f where
- class Functor11 f => Foldable11 f where
- newtype Lift1 a i = Lift1 {
- unLift1 :: a
- class Functor21 f => Foldable21 f where
- newtype Lift2 a i j = Lift2 {
- unLift2 :: a
- class Functor22 f => Foldable22 f where
- class Foldable11 t => Traversable11 t where
- class Foldable21 t => Traversable21 t where
- class Foldable22 t => Traversable22 t where
- data Some1 a = Some1 !(a i)
- data Some2 a = Some2 !(a i j)
- data Pair1 a b i = Pair1 (a i) (b i)
- fst1 :: Pair1 a b i -> a i
- snd1 :: Pair1 a b i -> b i
- data Pair2 a b i j = Pair2 (a i j) (b i j)
- fst2 :: Pair2 a b i j -> a i j
- snd2 :: Pair2 a b i j -> b i j
- type family (xs :: [k]) ++ (ys :: [k]) :: [k] where ...
- eqAppendIdentity :: proxy xs -> TypeEq xs (xs ++ '[])
- eqAppendAssoc :: proxy1 xs -> proxy2 ys -> proxy3 zs -> TypeEq ((xs ++ ys) ++ zs) (xs ++ (ys ++ zs))
- data List1 :: (k -> *) -> [k] -> * where
- append1 :: List1 a xs -> List1 a ys -> List1 a (xs ++ ys)
- newtype DList1 a xs = DList1 {}
- toList1 :: DList1 a xs -> List1 a xs
- fromList1 :: List1 a xs -> DList1 a xs
- dnil1 :: DList1 a '[]
- dcons1 :: a x -> DList1 a xs -> DList1 a (x ': xs)
- dsnoc1 :: DList1 a xs -> a x -> DList1 a (xs ++ '[x])
- dsingleton1 :: a x -> DList1 a '[x]
- dappend1 :: DList1 a xs -> DList1 a ys -> DList1 a (xs ++ ys)
Showing indexed types
Uniform variant of Show
for k
-indexed types. This differs
from transformers:
Show1
in being
polykinded, like it ought to be.
Alas, I don't think there's any way to derive instances the way
we can derive for Show
.
Show a => Show2 k2 k1 (Lift2 k2 k1 a) Source # | |
(Show2 k2 k1 a, Show2 k2 k1 b) => Show2 k2 k1 (Pair2 k2 k1 a b) Source # | |
Show2 Hakaru [Hakaru] Pattern Source # | |
Show2 Hakaru [Hakaru] (PDatumFun x) Source # | |
Show2 Hakaru [Hakaru] (PDatumStruct xs) Source # | |
Show2 Hakaru [Hakaru] (PDatumCode xss) Source # | |
(Show1 k (Sing k), Show1 k (syn (MemoizedABT k syn))) => Show2 k [k] (MemoizedABT k syn) Source # | |
(Show1 k (Sing k), Show1 k (syn (TrivialABT k syn))) => Show2 k [k] (TrivialABT k syn) Source # | |
(Show1 k (Sing k), Show1 k rec) => Show2 k [k] (View k rec) Source # | |
(Show1 k (Sing k), Show1 k (syn (MetaABT k meta syn)), Show meta) => Show2 k [k] (MetaABT k meta syn) Source # | |
Some more-generic helper functions for showing things
showListWith :: (a -> ShowS) -> [a] -> ShowS Source #
some helpers for implementing the instances
showParen_111 :: (Show1 a, Show1 b, Show1 c) => Int -> String -> a i -> b j -> c k -> ShowS Source #
Equality
Uniform variant of Eq
for homogeneous k
-indexed types.
N.B., we keep this separate from the JmEq1
class because for
some types we may be able to decide eq1
while not being able
to decide jmEq1
(e.g., if using phantom types rather than
GADTs). N.B., this function returns value/term equality! That
is, the following four laws must hold relating the Eq1
class
to the Eq
class:
- if
eq1 x y == True
, thenx
andy
have the same type index and(x == y) == True
- if
eq1 x y == False
wherex
andy
have the same type index, then(x == y) == False
- if
(x == y) == True
, theneq1 x y == True
- if
(x == y) == False
, theneq1 x y == False
Alas, I don't think there's any way to derive instances the way
we can derive for Eq
.
Eq2 Hakaru Hakaru Coercion Source # | |
Eq2 Hakaru Hakaru PrimCoercion Source # | |
Eq a => Eq2 k2 k1 (Lift2 k2 k1 a) Source # | |
Eq2 Hakaru [Hakaru] Pattern Source # | |
Eq2 Hakaru [Hakaru] MeasureOp Source # | |
Eq2 Hakaru [Hakaru] ArrayOp Source # | |
Eq2 Hakaru [Hakaru] PrimOp Source # | |
Eq2 Hakaru [Hakaru] (PDatumFun x) Source # | |
Eq2 Hakaru [Hakaru] (PDatumStruct xs) Source # | |
Eq2 Hakaru [Hakaru] (PDatumCode xss) Source # | |
data TypeEq :: k -> k -> * where Source #
Concrete proofs of type equality. In order to make use of a
proof p :: TypeEq a b
, you must pattern-match on the Refl
constructor in order to show GHC that the types a
and b
are
equal.
transitivity :: TypeEq a b -> TypeEq b c -> TypeEq a c Source #
Type equality is transitive. N.B., this is has a more general
type than (.)
congruence :: TypeEq a b -> TypeEq (f a) (f b) Source #
Type constructors are extensional.
class Eq1 a => JmEq1 a where Source #
Uniform variant of Eq
for heterogeneous k
-indexed types.
N.B., this function returns value/term equality! That is, the
following four laws must hold relating the JmEq1
class to the
Eq1
class:
- if
jmEq1 x y == Just Refl
, thenx
andy
have the same type index andeq1 x y == True
- if
jmEq1 x y == Nothing
wherex
andy
have the same type index, theneq1 x y == False
- if
eq1 x y == True
, thenjmEq1 x y == Just Refl
- if
eq1 x y == False
, thenjmEq1 x y == Nothing
Alas, I don't think there's any way to derive instances the way
we can derive for Eq
.
JmEq1 Hakaru HContinuous Source # | |
JmEq1 Hakaru HDiscrete Source # | |
JmEq1 Hakaru HIntegrable Source # | |
JmEq1 Hakaru HRadical Source # | |
JmEq1 Hakaru HFractional Source # | |
JmEq1 Hakaru HRing Source # | |
JmEq1 Hakaru HSemiring Source # | |
JmEq1 Hakaru NaryOp Source # | |
JmEq1 Hakaru Literal Source # | |
JmEq1 Symbol (Sing Symbol) Source # | |
JmEq1 HakaruCon (Sing HakaruCon) Source # | |
JmEq1 HakaruFun (Sing HakaruFun) Source # | |
JmEq1 Hakaru (Sing Hakaru) Source # | |
JmEq1 Hakaru (PrimCoercion a) Source # | |
Eq1 Hakaru ast => JmEq1 Hakaru (Datum ast) Source # | |
JmEq1 Untyped (Sing Untyped) Source # | |
JmEq1 [[HakaruFun]] (Sing [[HakaruFun]]) Source # | |
JmEq1 [HakaruFun] (Sing [HakaruFun]) Source # | |
JmEq1 k a => JmEq1 [k] (List1 k a) Source # | |
Generalized abstract nonsense
class Functor11 f where Source #
A functor on the category of k
-indexed types (i.e., from
k
-indexed types to k
-indexed types). We unify the two indices,
because that seems the most helpful for what we're doing; we
could, of course, offer a different variant that maps k1
-indexed
types to k2
-indexed types...
Alas, I don't think there's any way to derive instances the way
we can derive for Functor
.
hylo11 :: forall f a b j. Functor11 f => (forall i. a i -> f a i) -> (forall i. f b i -> b i) -> a j -> b j Source #
class Functor21 f where Source #
A functor from (k1,k2)
-indexed types to k3
-indexed types.
Functor21 Hakaru Hakaru [Hakaru] Term Source # | |
Functor21 Hakaru Hakaru [Hakaru] Lazy Source # | |
Functor21 Hakaru Hakaru [Hakaru] Whnf Source # | |
Functor21 Hakaru Hakaru [Hakaru] Head Source # | |
Functor21 Untyped Untyped [Untyped] Term Source # | |
Functor21 Hakaru Hakaru [Hakaru] (Branch a) Source # | |
Functor21 [([Hakaru], Hakaru)] Hakaru [Hakaru] SArgs Source # | |
class Functor11 f => Foldable11 f where Source #
A foldable functor on the category of k
-indexed types.
Alas, I don't think there's any way to derive instances the way
we can derive for Foldable
.
fold11 :: Monoid m => f (Lift1 m) i -> m Source #
foldMap11 :: Monoid m => (forall i. a i -> m) -> f a j -> m Source #
Foldable11 Hakaru Hakaru Datum Source # | |
Foldable11 Hakaru Hakaru (DatumFun x) Source # | |
Foldable11 Hakaru Hakaru (DatumStruct xs) Source # | |
Foldable11 Hakaru Hakaru (DatumCode xss) Source # | |
Foldable11 [k1] k1 (List1 k1) Source # | |
Any unindexed type can be lifted to be (trivially) k
-indexed.
class Functor21 f => Foldable21 f where Source #
fold21 :: Monoid m => f (Lift2 m) j -> m Source #
foldMap21 :: Monoid m => (forall h i. a h i -> m) -> f a j -> m Source #
Foldable21 Hakaru Hakaru [Hakaru] Term Source # | |
Foldable21 Hakaru Hakaru [Hakaru] Lazy Source # | |
Foldable21 Hakaru Hakaru [Hakaru] Whnf Source # | |
Foldable21 Hakaru Hakaru [Hakaru] Head Source # | |
Foldable21 Untyped Untyped [Untyped] Term Source # | |
Foldable21 Hakaru Hakaru [Hakaru] (Branch a) Source # | |
Foldable21 [([Hakaru], Hakaru)] Hakaru [Hakaru] SArgs Source # | |
Any unindexed type can be lifted to be (trivially) (k1,k2)
-indexed.
Eq a => Eq2 k2 k1 (Lift2 k2 k1 a) Source # | |
Show a => Show2 k2 k1 (Lift2 k2 k1 a) Source # | |
Eq a => Eq1 k (Lift2 k k1 a i) Source # | |
Show a => Show1 k (Lift2 k k1 a i) Source # | |
Eq a => Eq (Lift2 k2 k1 a i j) Source # | |
Ord a => Ord (Lift2 k2 k1 a i j) Source # | |
Read a => Read (Lift2 k2 k1 a i j) Source # | |
Show a => Show (Lift2 k2 k1 a i j) Source # | |
class Functor22 f => Foldable22 f where Source #
class Foldable11 t => Traversable11 t where Source #
traverse11 :: Applicative f => (forall i. a i -> f (b i)) -> t a j -> f (t b j) Source #
Traversable11 Hakaru Hakaru Datum Source # | |
Traversable11 Hakaru Hakaru (DatumFun x) Source # | |
Traversable11 Hakaru Hakaru (DatumStruct xs) Source # | |
Traversable11 Hakaru Hakaru (DatumCode xss) Source # | |
Traversable11 [k1] k1 (List1 k1) Source # | |
class Foldable21 t => Traversable21 t where Source #
traverse21 :: Applicative f => (forall h i. a h i -> f (b h i)) -> t a j -> f (t b j) Source #
class Foldable22 t => Traversable22 t where Source #
traverse22 :: Applicative f => (forall h i. a h i -> f (b h i)) -> t a j l -> f (t b j l) Source #
Helper types
Existentially quantify over a single index.
TODO: replace SomeVariable
with (Some1 Variable)
Some1 !(a i) |
Existentially quantify over two indices.
Some2 !(a i j) |
A lazy pairing of identically k
-indexed values.
Pair1 (a i) (b i) |
A lazy pairing of identically (k1,k2)
-indexed values.
Pair2 (a i j) (b i j) |
List types
eqAppendIdentity :: proxy xs -> TypeEq xs (xs ++ '[]) Source #
eqAppendAssoc :: proxy1 xs -> proxy2 ys -> proxy3 zs -> TypeEq ((xs ++ ys) ++ zs) (xs ++ (ys ++ zs)) Source #
(
is associative. This identity doesn't come for free
but rather must be proven.++
)
data List1 :: (k -> *) -> [k] -> * where Source #
A lazy list of k
-indexed elements, itself indexed by the
list of indices
Traversable11 [k1] k1 (List1 k1) Source # | |
Foldable11 [k1] k1 (List1 k1) Source # | |
Functor11 [k1] k1 (List1 k1) Source # | |
JmEq1 k a => JmEq1 [k] (List1 k a) Source # | |
Eq1 k a => Eq1 [k] (List1 k a) Source # | |
Show1 k a => Show1 [k] (List1 k a) Source # | |
Eq1 k a => Eq (List1 k a xs) Source # | |
Show1 k a => Show (List1 k a xs) Source # | |
A difference-list variant of List1
.
dsingleton1 :: a x -> DList1 a '[x] Source #