homoiconic-0.1.2.0: Constructs FAlgebras from typeclasses, making Haskell functions homoiconic

Safe HaskellNone
LanguageHaskell2010

Homoiconic.Constrained

Contents

Synopsis

Constrained FAlgebras

class Typeable alg => FAlgebra alg where Source #

Minimal complete definition

runSig1, runSig0, mapRun

Associated Types

data Sig alg (t :: [Tag]) a Source #

Methods

runSig1 :: alg a => proxy a -> Sig alg (s ': t) (AppTags t a) -> AppTags (s ': t) a Source #

runSig0 :: alg a => proxy a -> Sig alg t (AppTags t a) -> AppTags t a Source #

mapRun :: FreeConstraints t' a => (forall s. Free (Sig alg') s a -> AppTags s a) -> Sig alg t (Free (Sig alg') t' a) -> Sig alg t (AppTags t' a) Source #

type AST alg t a = Free (Sig alg) t a Source #

runAST :: forall alg t a. (FAlgebra alg, alg a) => Free (Sig alg) t a -> AppTags t a Source #

Dealing with Type Families

type Tag = Type Source #

This type synonym represents the kind of tags. Using this synonym requires the -XTypeInType extension.

NOTE: We would get more type safety if this were implemented as an open kind, but open kinds aren't yet implemented in GHC.

type family AppTag (t :: Tag) (a :: Type) Source #

Apply a single tag to a type

type family AppTags (t :: [Tag]) (a :: Type) :: Type where ... Source #

Apply a (possibly empty) list of tags to a type

Equations

AppTags '[] a = a 
AppTags (x ': xs) a = AppTag x (AppTags xs a) 

type family ConsTag (t :: Tag) (ts :: [Tag]) :: [Tag] Source #

An alternative method for constructing kinds of [Tag] that obeys the equality constraints

Constrained Free Monad

data Free f t a where Source #

The constrained free monad

Constructors

Free1 :: FreeConstraints t a => f (s ': t) (Free f t a) -> Free f (s ': t) a 
Free0 :: FreeConstraints t a => f t (Free f t a) -> Free f t a 
Pure :: AppTags t a -> Free f t a 

Instances

(Show (AppTags t a), Show (f t (Free f t a)), ShowUntag (f t (Free f t a))) => Show (Free f t a) Source # 

Methods

showsPrec :: Int -> Free f t a -> ShowS #

show :: Free f t a -> String #

showList :: [Free f t a] -> ShowS #

type family FreeConstraints (t :: [Tag]) (a :: Type) :: Constraint Source #

The constraints we are placing on the free monad

class MkFree s t a where Source #

mkFree is a smart constructor that is implemented by either Free1 or Free0 depending on how ConsTag is implemented

Minimal complete definition

mkFree

Methods

mkFree :: proxy s -> f (ConsTag s t) (Free f t a) -> Free f (ConsTag s t) a Source #

Converting between FAlgebras

class (FAlgebra alg1, FAlgebra alg2) => View alg1 t1 alg2 t2 where Source #

Minimal complete definition

embedSig, unsafeExtractSig

Methods

embedSig :: Sig alg1 t1 a -> Sig alg2 t2 a Source #

unsafeExtractSig :: Sig alg2 t2 a -> Sig alg1 t1 a Source #

Instances

FAlgebra alg => View alg t alg t Source # 

Methods

embedSig :: Sig alg t a -> Sig alg t a Source #

unsafeExtractSig :: Sig alg t a -> Sig alg t a Source #

Variable definitions

data Var Source #

Instances

Eq Var Source # 

Methods

(==) :: Var -> Var -> Bool #

(/=) :: Var -> Var -> Bool #

Show Var Source # 

Methods

showsPrec :: Int -> Var -> ShowS #

show :: Var -> String #

showList :: [Var] -> ShowS #

var1 :: AppTags t Var ~ Var => AST alg t Var Source #

var2 :: AppTags t Var ~ Var => AST alg t Var Source #

var3 :: AppTags t Var ~ Var => AST alg t Var Source #

Template Haskell

mkFAlgebra :: Name -> Q [Dec] Source #

Generates the FAlgebra instance for the specified name and all of its dependencies recursively

mkTag :: Name -> Q [Dec] Source #

Constructs the needed declarations for a type family assuming no constraints on the type family

mkTagFromCnst :: Name -> Q Pred -> Q [Dec] Source #

This functions is designed to be called on non-associated type families only. The second argument lists the constraints that the family must obey. For example:

mkTagFromCnst ''Scalar [t| forall a. Scalar (Scalar a) ~ Scalar a |]

Helper functions

unsafeExtractSigTag0 :: View alg1 '[] alg2 t => Sig alg2 t (Free (Sig alg2) t a) -> Sig alg1 '[] (Free (Sig alg2) t a) Source #

unsafeExtractSigTag :: View alg1 '[s] alg2 (s ': t) => Sig alg2 (s ': t) (Free (Sig alg2) t a) -> Sig alg1 '[s] (Free (Sig alg2) t a) Source #

unsafeCoerceSigTag :: proxy t' -> Sig alg t a -> Sig alg t' a Source #

runSig1Snoc :: forall proxy alg a s ttt t u. (FAlgebra alg, alg (AppTag u a)) => Proxy (u :: Tag) -> Proxy (s :: Tag) -> Proxy (t :: [Tag]) -> Proxy a -> Sig alg ttt (AppTags t a) -> AppTag s (AppTags t a) Source #

runSig0Snoc :: forall proxy alg a t u. (FAlgebra alg, alg (AppTag u a)) => Proxy u -> Proxy a -> Sig alg t (AppTags (t `Snoc` u) a) -> AppTags (t `Snoc` u) a Source #

embedSigTag :: View alg1 (t ': t1) alg2 (t ': t2) => Sig alg1 (t ': t1) a -> Sig alg2 (t ': t2) a Source #

type family Snoc (xs :: [k]) (y :: k) where ... Source #

Append an element to the end of a type list

Equations

Snoc '[] y = '[y] 
Snoc (x ': xs) y = x ': Snoc xs y 

Other need types

data Proxy k t :: forall k. k -> * #

A concrete, poly-kinded proxy type

Constructors

Proxy 

Instances

Monad (Proxy *) 

Methods

(>>=) :: Proxy * a -> (a -> Proxy * b) -> Proxy * b #

(>>) :: Proxy * a -> Proxy * b -> Proxy * b #

return :: a -> Proxy * a #

fail :: String -> Proxy * a #

Functor (Proxy *) 

Methods

fmap :: (a -> b) -> Proxy * a -> Proxy * b #

(<$) :: a -> Proxy * b -> Proxy * a #

Applicative (Proxy *) 

Methods

pure :: a -> Proxy * a #

(<*>) :: Proxy * (a -> b) -> Proxy * a -> Proxy * b #

(*>) :: Proxy * a -> Proxy * b -> Proxy * b #

(<*) :: Proxy * a -> Proxy * b -> Proxy * a #

Foldable (Proxy *) 

Methods

fold :: Monoid m => Proxy * m -> m #

foldMap :: Monoid m => (a -> m) -> Proxy * a -> m #

foldr :: (a -> b -> b) -> b -> Proxy * a -> b #

foldr' :: (a -> b -> b) -> b -> Proxy * a -> b #

foldl :: (b -> a -> b) -> b -> Proxy * a -> b #

foldl' :: (b -> a -> b) -> b -> Proxy * a -> b #

foldr1 :: (a -> a -> a) -> Proxy * a -> a #

foldl1 :: (a -> a -> a) -> Proxy * a -> a #

toList :: Proxy * a -> [a] #

null :: Proxy * a -> Bool #

length :: Proxy * a -> Int #

elem :: Eq a => a -> Proxy * a -> Bool #

maximum :: Ord a => Proxy * a -> a #

minimum :: Ord a => Proxy * a -> a #

sum :: Num a => Proxy * a -> a #

product :: Num a => Proxy * a -> a #

Traversable (Proxy *) 

Methods

traverse :: Applicative f => (a -> f b) -> Proxy * a -> f (Proxy * b) #

sequenceA :: Applicative f => Proxy * (f a) -> f (Proxy * a) #

mapM :: Monad m => (a -> m b) -> Proxy * a -> m (Proxy * b) #

sequence :: Monad m => Proxy * (m a) -> m (Proxy * a) #

Generic1 (Proxy *) 

Associated Types

type Rep1 (Proxy * :: * -> *) :: * -> * #

Methods

from1 :: Proxy * a -> Rep1 (Proxy *) a #

to1 :: Rep1 (Proxy *) a -> Proxy * a #

Alternative (Proxy *) 

Methods

empty :: Proxy * a #

(<|>) :: Proxy * a -> Proxy * a -> Proxy * a #

some :: Proxy * a -> Proxy * [a] #

many :: Proxy * a -> Proxy * [a] #

MonadPlus (Proxy *) 

Methods

mzero :: Proxy * a #

mplus :: Proxy * a -> Proxy * a -> Proxy * a #

Bounded (Proxy k s) 

Methods

minBound :: Proxy k s #

maxBound :: Proxy k s #

Enum (Proxy k s) 

Methods

succ :: Proxy k s -> Proxy k s #

pred :: Proxy k s -> Proxy k s #

toEnum :: Int -> Proxy k s #

fromEnum :: Proxy k s -> Int #

enumFrom :: Proxy k s -> [Proxy k s] #

enumFromThen :: Proxy k s -> Proxy k s -> [Proxy k s] #

enumFromTo :: Proxy k s -> Proxy k s -> [Proxy k s] #

enumFromThenTo :: Proxy k s -> Proxy k s -> Proxy k s -> [Proxy k s] #

Eq (Proxy k s) 

Methods

(==) :: Proxy k s -> Proxy k s -> Bool #

(/=) :: Proxy k s -> Proxy k s -> Bool #

Ord (Proxy k s) 

Methods

compare :: Proxy k s -> Proxy k s -> Ordering #

(<) :: Proxy k s -> Proxy k s -> Bool #

(<=) :: Proxy k s -> Proxy k s -> Bool #

(>) :: Proxy k s -> Proxy k s -> Bool #

(>=) :: Proxy k s -> Proxy k s -> Bool #

max :: Proxy k s -> Proxy k s -> Proxy k s #

min :: Proxy k s -> Proxy k s -> Proxy k s #

Read (Proxy k s) 
Show (Proxy k s) 

Methods

showsPrec :: Int -> Proxy k s -> ShowS #

show :: Proxy k s -> String #

showList :: [Proxy k s] -> ShowS #

Ix (Proxy k s) 

Methods

range :: (Proxy k s, Proxy k s) -> [Proxy k s] #

index :: (Proxy k s, Proxy k s) -> Proxy k s -> Int #

unsafeIndex :: (Proxy k s, Proxy k s) -> Proxy k s -> Int

inRange :: (Proxy k s, Proxy k s) -> Proxy k s -> Bool #

rangeSize :: (Proxy k s, Proxy k s) -> Int #

unsafeRangeSize :: (Proxy k s, Proxy k s) -> Int

Generic (Proxy k t) 

Associated Types

type Rep (Proxy k t) :: * -> * #

Methods

from :: Proxy k t -> Rep (Proxy k t) x #

to :: Rep (Proxy k t) x -> Proxy k t #

Monoid (Proxy k s) 

Methods

mempty :: Proxy k s #

mappend :: Proxy k s -> Proxy k s -> Proxy k s #

mconcat :: [Proxy k s] -> Proxy k s #

type Rep1 (Proxy *) 
type Rep1 (Proxy *) = D1 (MetaData "Proxy" "Data.Proxy" "base" False) (C1 (MetaCons "Proxy" PrefixI False) U1)
type Rep (Proxy k t) 
type Rep (Proxy k t) = D1 (MetaData "Proxy" "Data.Proxy" "base" False) (C1 (MetaCons "Proxy" PrefixI False) U1)

class Typeable k a #

The class Typeable allows a concrete representation of a type to be calculated.

Minimal complete definition

typeRep#

data Constraint :: * #

The kind of constraints, like Show a