-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Open algebraic data type examples. -- -- Example usage of open-adt with haddock documentation. Read the -- Data.OpenADT.Tutorial module from top to bottom. @package open-adt-tutorial @version 1.0 module Data.OpenADT.Tutorial -- | A type alias to reduce typing when writing the types of algebras. type Alg f x = f x -> x -- | The base case of a list type. data NilF x NilF' :: NilF x -- | A one element cons element. data Cons1F a x Cons1F' :: a -> x -> Cons1F a x -- | A two element cons element. data Cons2F a x Cons2F' :: a -> a -> x -> Cons2F a x -- | The row of the first list type. It defines a "standard" list type. type List1RowF a = ("nilF" .== NilF .+ "cons1F" .== Cons1F a) -- | The row of the second list type. This type re-uses the constructors of -- List1RowF and includes a third constructor: a two element cons. type List2RowF a = ("nilF" .== NilF .+ "cons1F" .== Cons1F a .+ "cons2F" .== Cons2F a) -- | The base functor of the List1 type. It is a VarF with -- the row List1RowF. type List1F a = VarF (List1RowF a) -- | A list type. We obtain this type by taking the fixed point of its base -- functor. type List1 a = Fix (VarF (List1RowF a)) -- | The base functor of the List2 type. type List2F a = VarF (List2RowF a) -- | A list type with a two element cons. This type is defined with the -- OpenADT synonym, which is simply conveinience for Fix (VarF -- r). type List2 a = OpenADT (List2RowF a) -- | Construct a List1. The patterns Cons1 and Nil are -- used. -- --
--   >>> print exList1
--   Fix (VarF (Cons1F' 0 (Fix (VarF (Cons1F' 1 (Fix (VarF NilF')))))))
--   
exList1 :: List1 Int -- | Construct a List2. -- --
--   >>> print exList2
--   Fix (VarF (Cons2F' 2 3 (Fix (VarF (Cons1F' 4 (Fix (VarF NilF')))))))
--   
exList2 :: List2 Int -- | The constructor Cons2F is added to exList1 without -- changing its structure. -- --
--   >>> print result1
--   Fix (VarF (Cons1F' 0 (Fix (VarF (Cons1F' 1 (Fix (VarF NilF')))))))
--   
result1 :: List2 Int -- | Remove a constructor using reduceVarF to convert a List2 -- to a List1. -- --
--   >>> print result2
--   Fix (VarF (Cons1F' 2 (Fix (VarF (Cons1F' 3 (Fix (VarF (Cons1F' 4 (Fix (VarF NilF'))))))))))
--   
result2 :: List1 Int -- | Use "traditional" pattern matching to write an algebra over a -- List1. -- --
--   >>> print result3
--   Fix (VarF (Cons2F' 0 0 (Fix (VarF (Cons2F' 1 1 (Fix (VarF NilF')))))))
--   
result3 :: List2 Int -- | An alternative way of writing result3 using caseonF. -- --
--   >>> print result4
--   Fix (VarF (Cons2F' 0 0 (Fix (VarF (Cons2F' 1 1 (Fix (VarF NilF')))))))
--   
result4 :: List2 Int -- | This type class defines a fmap-like operation over lists. class OverList a a' r (f :: * -> *) fmapList' :: OverList a a' r f => (a -> a') -> f (OpenADT r) -> OpenADT r -- | Apply the fmapList' function to any (OpenADT r) -- provided all its constructors satisfy the constraint (OverList a -- a' s). fmapList :: forall a a' r s. (Forall r Functor, Forall r (OverList a a' s)) => (a -> a') -> OpenADT r -> OpenADT s -- | Demonstrate that fmapList can be applied to exList1. -- --
--   result5 = fmapList (show @Int) exList1 :: List1 String
--   
-- --
--   >>> print result5
--   Fix (VarF (Cons1F' "0" (Fix (VarF (Cons1F' "1" (Fix (VarF NilF')))))))
--   
result5 :: List1 String -- | Demonstrate that fmapList can be applied to exList2. -- --
--   result6 = fmapList (show @Int) exList2 :: List2 String
--   
-- --
--   >>> print result6
--   Fix (VarF (Cons2F' "2" "3" (Fix (VarF (Cons1F' "4" (Fix (VarF NilF')))))))
--   
result6 :: List2 String -- | Demonstrate how to handle subsets of a VarF individually. -- -- Below is an alternate, but identical, implementation for the case -- where one subset of variants matched is a single variant -- (trialF is used instead of multiTrialF). -- --
--   result7 = cata alg exList2 where
--     alg w = case trialF w #cons2F of
--       Left (Cons2F' a b x) -> Cons1 ("(" <> show a <> " : " <> show b <> ")") x
--       Right leftovers -> fmapList' (show @Int) leftovers
--   
-- --
--   >>> print result7
--   Fix (VarF (Cons1F' "(2 : 3)" (Fix (VarF (Cons1F' "4" (Fix (VarF NilF')))))))
--   
result7 :: List1 String -- | This is the function invoked by the executable in this package. It -- simply prints out the examples. main' :: IO () instance Data.OpenADT.VarF.OpenAlg r "nilF" Data.OpenADT.Tutorial.NilF (Data.OpenADT.OpenADT r) => Data.OpenADT.Tutorial.OverList a a' r Data.OpenADT.Tutorial.NilF instance Data.OpenADT.VarF.OpenAlg r "cons1F" (Data.OpenADT.Tutorial.Cons1F a') (Data.OpenADT.OpenADT r) => Data.OpenADT.Tutorial.OverList a a' r (Data.OpenADT.Tutorial.Cons1F a) instance Data.OpenADT.VarF.OpenAlg r "cons2F" (Data.OpenADT.Tutorial.Cons2F a') (Data.OpenADT.OpenADT r) => Data.OpenADT.Tutorial.OverList a a' r (Data.OpenADT.Tutorial.Cons2F a) instance Data.Row.Internal.Forall v (Data.OpenADT.Tutorial.OverList a a' r) => Data.OpenADT.Tutorial.OverList a a' r (Data.OpenADT.VarF.VarF v) instance GHC.Show.Show a => Data.Functor.Classes.Show1 (Data.OpenADT.Tutorial.Cons2F a) instance GHC.Show.Show a => Data.Functor.Classes.Show1 (Data.OpenADT.Tutorial.Cons1F a) instance Data.Functor.Classes.Show1 Data.OpenADT.Tutorial.NilF instance GHC.Classes.Eq a => Data.Functor.Classes.Eq1 (Data.OpenADT.Tutorial.Cons2F a) instance GHC.Classes.Eq a => Data.Functor.Classes.Eq1 (Data.OpenADT.Tutorial.Cons1F a) instance Data.Functor.Classes.Eq1 Data.OpenADT.Tutorial.NilF instance (GHC.Show.Show a, GHC.Show.Show x) => GHC.Show.Show (Data.OpenADT.Tutorial.Cons2F a x) instance GHC.Base.Functor (Data.OpenADT.Tutorial.Cons2F a) instance (GHC.Classes.Eq a, GHC.Classes.Eq x) => GHC.Classes.Eq (Data.OpenADT.Tutorial.Cons2F a x) instance (GHC.Show.Show a, GHC.Show.Show x) => GHC.Show.Show (Data.OpenADT.Tutorial.Cons1F a x) instance GHC.Base.Functor (Data.OpenADT.Tutorial.Cons1F a) instance (GHC.Classes.Eq a, GHC.Classes.Eq x) => GHC.Classes.Eq (Data.OpenADT.Tutorial.Cons1F a x) instance GHC.Show.Show (Data.OpenADT.Tutorial.NilF x) instance GHC.Base.Functor Data.OpenADT.Tutorial.NilF instance GHC.Classes.Eq (Data.OpenADT.Tutorial.NilF x)