From e0718f203f2448ba2029e70d14aed075860b7fac Mon Sep 17 00:00:00 2001 From: nand Date: Tue, 4 Feb 2014 22:13:27 +0100 Subject: Add support for type/data families This adds support for type/data families with their respective instances, as well as closed type families and associated type/data families. Signed-off-by: Mateusz Kowalczyk --- html-test/src/TypeFamilies.hs | 76 +++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 18 deletions(-) (limited to 'html-test/src/TypeFamilies.hs') diff --git a/html-test/src/TypeFamilies.hs b/html-test/src/TypeFamilies.hs index 561f95fd..725e76a7 100644 --- a/html-test/src/TypeFamilies.hs +++ b/html-test/src/TypeFamilies.hs @@ -1,28 +1,68 @@ -{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeFamilies, UndecidableInstances #-} +-- | Doc for: module TypeFamilies module TypeFamilies where --- | Type family G -type family G a :: * +-- | Doc for: data X +data X + = X -- ^ Doc for: X + | XX -- ^ Doc for: XX + | XXX -- ^ Doc for: XXX --- | A class with an associated type -class A a where - -- | An associated type - data B a :: * -> * - -- | A method - f :: B a Int +-- | Doc for: data Y +data Y --- | Doc for family -type family F a +-- | Doc for: class Test a +class Test a +-- | Doc for: instance Test X +instance Test X +-- | Doc for: instance Test Y +instance Test Y --- | Doc for G Int -type instance G Int = Bool -type instance G Float = Int +-- | Doc for: type family Foo a +type family Foo a +-- | Doc for: type instance Foo X = Y +type instance Foo X = Y +-- | Doc for: type instance Foo Y = X +type instance Foo Y = X -instance A Int where - data B Int x = Con x - f = Con 3 +-- | Doc for: data family Bat a +data family Bat a :: * -g = Con 5 +-- | Doc for: data instance Bat X +data instance Bat X + = BatX X -- ^ Doc for: BatX X + | BatXX { aaa :: X , bbb :: Y } -- ^ Doc for: BatXX { ... } + +-- | Doc for: data instance Bat Y +data instance Bat Y + = BatY Y -- ^ Doc for: BatY Y + | X :+ X -- X :+ X + +-- | Doc for: class Assoc a +class Assoc a where + -- | Doc for: data AssocD a + data AssocD a :: * + -- | Doc for: type AssocT a + type AssocT a :: * + +-- | Doc for: instance Assoc X +instance Assoc X where + -- | Doc for: data AssocD X = AssocX + data AssocD X = AssocX -- ^ Doc for: AssocX + -- | Doc for: type AssocT X = Foo X + type AssocT X = Foo X + +-- | Doc for: instance Assoc Y +instance Assoc Y where + -- | Doc for: data AssocD Y = AssocY + data AssocD Y = AssocY -- ^ Doc for: AssocY + -- | Doc for: type AssocT Y = Bat Y + type AssocT Y = Bat Y + +-- | Doc for: type family Bar b +type family Bar b where + Bar X = X + Bar y = Y -- cgit v1.2.3