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

Safe HaskellNone
LanguageHaskell2010

Homoiconic.Heterogeneous

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 :: (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 #

Instances

FAlgebra Floating Source # 

Associated Types

data Sig (Floating :: Type -> Constraint) (t :: [Tag]) a :: * Source #

Methods

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

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

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

FAlgebra Fractional Source # 

Associated Types

data Sig (Fractional :: Type -> Constraint) (t :: [Tag]) a :: * Source #

Methods

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

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

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

FAlgebra Num Source # 

Associated Types

data Sig (Num :: Type -> Constraint) (t :: [Tag]) a :: * Source #

Methods

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

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

mapRun :: (forall s. Free (Sig alg') s a -> AppTags s a) -> Sig Num t (Free (Sig alg') t' a) -> Sig Num 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) 

Heterogeneous Free Monad

data Free f t a where Source #

Constructors

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

Instances

(View Floating ([] Tag) alg' t, View Fractional ([] Tag) alg' t, View Num ([] Tag) alg' t) => Floating (Free (Sig alg') t a) Source # 

Methods

pi :: Free (Sig alg') t a #

exp :: Free (Sig alg') t a -> Free (Sig alg') t a #

log :: Free (Sig alg') t a -> Free (Sig alg') t a #

sqrt :: Free (Sig alg') t a -> Free (Sig alg') t a #

(**) :: Free (Sig alg') t a -> Free (Sig alg') t a -> Free (Sig alg') t a #

logBase :: Free (Sig alg') t a -> Free (Sig alg') t a -> Free (Sig alg') t a #

sin :: Free (Sig alg') t a -> Free (Sig alg') t a #

cos :: Free (Sig alg') t a -> Free (Sig alg') t a #

tan :: Free (Sig alg') t a -> Free (Sig alg') t a #

asin :: Free (Sig alg') t a -> Free (Sig alg') t a #

acos :: Free (Sig alg') t a -> Free (Sig alg') t a #

atan :: Free (Sig alg') t a -> Free (Sig alg') t a #

sinh :: Free (Sig alg') t a -> Free (Sig alg') t a #

cosh :: Free (Sig alg') t a -> Free (Sig alg') t a #

tanh :: Free (Sig alg') t a -> Free (Sig alg') t a #

asinh :: Free (Sig alg') t a -> Free (Sig alg') t a #

acosh :: Free (Sig alg') t a -> Free (Sig alg') t a #

atanh :: Free (Sig alg') t a -> Free (Sig alg') t a #

log1p :: Free (Sig alg') t a -> Free (Sig alg') t a #

expm1 :: Free (Sig alg') t a -> Free (Sig alg') t a #

log1pexp :: Free (Sig alg') t a -> Free (Sig alg') t a #

log1mexp :: Free (Sig alg') t a -> Free (Sig alg') t a #

(View Fractional ([] Tag) alg' t, View Num ([] Tag) alg' t) => Fractional (Free (Sig alg') t a) Source # 

Methods

(/) :: Free (Sig alg') t a -> Free (Sig alg') t a -> Free (Sig alg') t a #

recip :: Free (Sig alg') t a -> Free (Sig alg') t a #

fromRational :: Rational -> Free (Sig alg') t a #

View Num ([] Tag) alg' t => Num (Free (Sig alg') t a) Source # 

Methods

(+) :: Free (Sig alg') t a -> Free (Sig alg') t a -> Free (Sig alg') t a #

(-) :: Free (Sig alg') t a -> Free (Sig alg') t a -> Free (Sig alg') t a #

(*) :: Free (Sig alg') t a -> Free (Sig alg') t a -> Free (Sig alg') t a #

negate :: Free (Sig alg') t a -> Free (Sig alg') t a #

abs :: Free (Sig alg') t a -> Free (Sig alg') t a #

signum :: Free (Sig alg') t a -> Free (Sig alg') t a #

fromInteger :: Integer -> Free (Sig alg') t a #

(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 #

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 #

View Fractional ([] Tag) Floating ([] Tag) Source # 
View Num ([] Tag) Floating ([] Tag) Source # 
View Num ([] Tag) Fractional ([] Tag) 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

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

Constructs the needed declarations for a type family

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