module Language.Haskell.Exts.Build (
name,
sym,
var,
op,
qvar,
pvar,
app,
infixApp,
appFun,
pApp,
tuple,
pTuple,
varTuple,
pvarTuple,
function,
strE,
charE,
intE,
strP,
charP,
intP,
doE,
lamE,
letE,
caseE,
alt,
altGW,
listE,
eList,
peList,
paren,
pParen,
qualStmt,
genStmt,
letStmt,
binds,
noBinds,
wildcard,
genNames,
sfun,
simpleFun,
patBind,
patBindWhere,
nameBind,
metaFunction,
metaConPat
) where
import Language.Haskell.Exts.Syntax
name :: String -> Name ()
name :: String -> Name ()
name = forall l. l -> String -> Name l
Ident ()
sym :: String -> Name ()
sym :: String -> Name ()
sym = forall l. l -> String -> Name l
Symbol ()
var :: Name () -> Exp ()
var :: Name () -> Exp ()
var = forall l. l -> QName l -> Exp l
Var () forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l. l -> Name l -> QName l
UnQual ()
op :: Name () -> QOp ()
op :: Name () -> QOp ()
op = forall l. l -> QName l -> QOp l
QVarOp () forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l. l -> Name l -> QName l
UnQual ()
qvar :: ModuleName () -> Name () -> Exp ()
qvar :: ModuleName () -> Name () -> Exp ()
qvar ModuleName ()
m Name ()
n = forall l. l -> QName l -> Exp l
Var () forall a b. (a -> b) -> a -> b
$ forall l. l -> ModuleName l -> Name l -> QName l
Qual () ModuleName ()
m Name ()
n
pvar :: Name () -> Pat ()
pvar :: Name () -> Pat ()
pvar = forall l. l -> Name l -> Pat l
PVar ()
app :: Exp () -> Exp () -> Exp ()
app :: Exp () -> Exp () -> Exp ()
app = forall l. l -> Exp l -> Exp l -> Exp l
App ()
infixApp :: Exp () -> QOp () -> Exp () -> Exp ()
infixApp :: Exp () -> QOp () -> Exp () -> Exp ()
infixApp = forall l. l -> Exp l -> QOp l -> Exp l -> Exp l
InfixApp ()
appFun :: Exp () -> [Exp ()] -> Exp ()
appFun :: Exp () -> [Exp ()] -> Exp ()
appFun Exp ()
f [] = Exp ()
f
appFun Exp ()
f (Exp ()
a:[Exp ()]
as) = Exp () -> [Exp ()] -> Exp ()
appFun (Exp () -> Exp () -> Exp ()
app Exp ()
f Exp ()
a) [Exp ()]
as
pApp :: Name () -> [Pat ()] -> Pat ()
pApp :: Name () -> [Pat ()] -> Pat ()
pApp Name ()
n [Pat ()]
ps = forall l. l -> QName l -> [Pat l] -> Pat l
PApp () (forall l. l -> Name l -> QName l
UnQual () Name ()
n) [Pat ()]
ps
tuple :: [Exp ()] -> Exp ()
tuple :: [Exp ()] -> Exp ()
tuple = forall l. l -> Boxed -> [Exp l] -> Exp l
Tuple () Boxed
Boxed
pTuple :: [Pat ()] -> Pat ()
pTuple :: [Pat ()] -> Pat ()
pTuple = forall l. l -> Boxed -> [Pat l] -> Pat l
PTuple () Boxed
Boxed
varTuple :: [Name ()] -> Exp ()
varTuple :: [Name ()] -> Exp ()
varTuple [Name ()]
ns = [Exp ()] -> Exp ()
tuple forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Name () -> Exp ()
var [Name ()]
ns
pvarTuple :: [Name ()] -> Pat ()
pvarTuple :: [Name ()] -> Pat ()
pvarTuple [Name ()]
ns = [Pat ()] -> Pat ()
pTuple forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Name () -> Pat ()
pvar [Name ()]
ns
function :: String -> Exp ()
function :: String -> Exp ()
function = Name () -> Exp ()
var forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l. l -> String -> Name l
Ident ()
strE :: String -> Exp ()
strE :: String -> Exp ()
strE String
s = forall l. l -> Literal l -> Exp l
Lit () (forall l. l -> String -> String -> Literal l
String () String
s String
s)
charE :: Char -> Exp ()
charE :: Char -> Exp ()
charE Char
c = forall l. l -> Literal l -> Exp l
Lit () (forall l. l -> Char -> String -> Literal l
Char () Char
c [Char
c])
intE :: Integer -> Exp ()
intE :: Integer -> Exp ()
intE Integer
n = forall l. l -> Literal l -> Exp l
Lit () (forall l. l -> Integer -> String -> Literal l
Int () Integer
n (forall a. Show a => a -> String
show Integer
n))
strP :: String -> Pat ()
strP :: String -> Pat ()
strP String
s = forall l. l -> Sign l -> Literal l -> Pat l
PLit () (forall l. l -> Sign l
Signless ()) (forall l. l -> String -> String -> Literal l
String () String
s String
s)
charP :: Char -> Pat ()
charP :: Char -> Pat ()
charP Char
x = forall l. l -> Sign l -> Literal l -> Pat l
PLit () (forall l. l -> Sign l
Signless ()) (forall l. l -> Char -> String -> Literal l
Char () Char
x [Char
x])
intP :: Integer -> Pat ()
intP :: Integer -> Pat ()
intP Integer
x = forall l. l -> Sign l -> Literal l -> Pat l
PLit ()
(if Integer
x forall a. Ord a => a -> a -> Bool
>= Integer
0 then forall l. l -> Sign l
Signless () else forall l. l -> Sign l
Negative ())
(forall l. l -> Integer -> String -> Literal l
Int () (forall a. Num a => a -> a
abs Integer
x) (forall a. Show a => a -> String
show Integer
x))
doE :: [Stmt ()] -> Exp ()
doE :: [Stmt ()] -> Exp ()
doE = forall l. l -> [Stmt l] -> Exp l
Do ()
lamE :: [Pat ()] -> Exp () -> Exp ()
lamE :: [Pat ()] -> Exp () -> Exp ()
lamE = forall l. l -> [Pat l] -> Exp l -> Exp l
Lambda ()
letE :: [Decl ()] -> Exp () -> Exp ()
letE :: [Decl ()] -> Exp () -> Exp ()
letE [Decl ()]
ds Exp ()
e = forall l. l -> Binds l -> Exp l -> Exp l
Let () ([Decl ()] -> Binds ()
binds [Decl ()]
ds) Exp ()
e
caseE :: Exp () -> [Alt ()] -> Exp ()
caseE :: Exp () -> [Alt ()] -> Exp ()
caseE = forall l. l -> Exp l -> [Alt l] -> Exp l
Case ()
alt :: Pat () -> Exp () -> Alt ()
alt :: Pat () -> Exp () -> Alt ()
alt Pat ()
p Exp ()
e = forall l. l -> Pat l -> Rhs l -> Maybe (Binds l) -> Alt l
Alt () Pat ()
p (Exp () -> Rhs ()
unGAlt Exp ()
e) Maybe (Binds ())
noBinds
altGW :: Pat () -> [Stmt ()] -> Exp () -> Binds () -> Alt ()
altGW :: Pat () -> [Stmt ()] -> Exp () -> Binds () -> Alt ()
altGW Pat ()
p [Stmt ()]
gs Exp ()
e Binds ()
w = forall l. l -> Pat l -> Rhs l -> Maybe (Binds l) -> Alt l
Alt () Pat ()
p ([Stmt ()] -> Exp () -> Rhs ()
gAlt [Stmt ()]
gs Exp ()
e) (forall a. a -> Maybe a
Just Binds ()
w)
unGAlt :: Exp () -> Rhs ()
unGAlt :: Exp () -> Rhs ()
unGAlt = forall l. l -> Exp l -> Rhs l
UnGuardedRhs ()
gAlts :: [([Stmt ()],Exp ())] -> Rhs ()
gAlts :: [([Stmt ()], Exp ())] -> Rhs ()
gAlts [([Stmt ()], Exp ())]
as = forall l. l -> [GuardedRhs l] -> Rhs l
GuardedRhss () forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\([Stmt ()]
gs,Exp ()
e) -> forall l. l -> [Stmt l] -> Exp l -> GuardedRhs l
GuardedRhs () [Stmt ()]
gs Exp ()
e) [([Stmt ()], Exp ())]
as
gAlt :: [Stmt ()] -> Exp () -> Rhs ()
gAlt :: [Stmt ()] -> Exp () -> Rhs ()
gAlt [Stmt ()]
gs Exp ()
e = [([Stmt ()], Exp ())] -> Rhs ()
gAlts [([Stmt ()]
gs,Exp ()
e)]
listE :: [Exp ()] -> Exp ()
listE :: [Exp ()] -> Exp ()
listE = forall l. l -> [Exp l] -> Exp l
List ()
eList :: Exp ()
eList :: Exp ()
eList = forall l. l -> [Exp l] -> Exp l
List () []
peList :: Pat ()
peList :: Pat ()
peList = forall l. l -> [Pat l] -> Pat l
PList () []
paren :: Exp () -> Exp ()
paren :: Exp () -> Exp ()
paren = forall l. l -> Exp l -> Exp l
Paren ()
pParen :: Pat () -> Pat ()
pParen :: Pat () -> Pat ()
pParen = forall l. l -> Pat l -> Pat l
PParen ()
qualStmt :: Exp () -> Stmt ()
qualStmt :: Exp () -> Stmt ()
qualStmt = forall l. l -> Exp l -> Stmt l
Qualifier ()
genStmt :: Pat () -> Exp () -> Stmt ()
genStmt :: Pat () -> Exp () -> Stmt ()
genStmt = forall l. l -> Pat l -> Exp l -> Stmt l
Generator ()
letStmt :: [Decl ()] -> Stmt ()
letStmt :: [Decl ()] -> Stmt ()
letStmt [Decl ()]
ds = forall l. l -> Binds l -> Stmt l
LetStmt () forall a b. (a -> b) -> a -> b
$ [Decl ()] -> Binds ()
binds [Decl ()]
ds
binds :: [Decl ()] -> Binds ()
binds :: [Decl ()] -> Binds ()
binds = forall l. l -> [Decl l] -> Binds l
BDecls ()
noBinds :: Maybe (Binds ())
noBinds :: Maybe (Binds ())
noBinds = forall a. Maybe a
Nothing
wildcard :: Pat ()
wildcard :: Pat ()
wildcard = forall l. l -> Pat l
PWildCard ()
genNames :: String -> Int -> [Name ()]
genNames :: String -> Int -> [Name ()]
genNames String
s Int
k = [ forall l. l -> String -> Name l
Ident () forall a b. (a -> b) -> a -> b
$ String
s forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
i | Int
i <- [Int
1..Int
k] ]
sfun :: Name () -> [Name ()] -> (Rhs ()) -> Maybe (Binds ()) -> Decl ()
sfun :: Name () -> [Name ()] -> Rhs () -> Maybe (Binds ()) -> Decl ()
sfun Name ()
f [Name ()]
pvs Rhs ()
rhs Maybe (Binds ())
bs = forall l. l -> [Match l] -> Decl l
FunBind () [forall l.
l -> Name l -> [Pat l] -> Rhs l -> Maybe (Binds l) -> Match l
Match () Name ()
f (forall a b. (a -> b) -> [a] -> [b]
map Name () -> Pat ()
pvar [Name ()]
pvs) Rhs ()
rhs Maybe (Binds ())
bs]
simpleFun :: Name () -> Name () -> Exp () -> Decl ()
simpleFun :: Name () -> Name () -> Exp () -> Decl ()
simpleFun Name ()
f Name ()
a Exp ()
e = let rhs :: Rhs ()
rhs = forall l. l -> Exp l -> Rhs l
UnGuardedRhs () Exp ()
e
in Name () -> [Name ()] -> Rhs () -> Maybe (Binds ()) -> Decl ()
sfun Name ()
f [Name ()
a] Rhs ()
rhs Maybe (Binds ())
noBinds
patBind :: Pat () -> Exp () -> Decl ()
patBind :: Pat () -> Exp () -> Decl ()
patBind Pat ()
p Exp ()
e = let rhs :: Rhs ()
rhs = forall l. l -> Exp l -> Rhs l
UnGuardedRhs () Exp ()
e
in forall l. l -> Pat l -> Rhs l -> Maybe (Binds l) -> Decl l
PatBind () Pat ()
p Rhs ()
rhs Maybe (Binds ())
noBinds
patBindWhere :: Pat () -> Exp () -> [Decl ()] -> Decl ()
patBindWhere :: Pat () -> Exp () -> [Decl ()] -> Decl ()
patBindWhere Pat ()
p Exp ()
e [Decl ()]
ds = let rhs :: Rhs ()
rhs = forall l. l -> Exp l -> Rhs l
UnGuardedRhs () Exp ()
e
in forall l. l -> Pat l -> Rhs l -> Maybe (Binds l) -> Decl l
PatBind () Pat ()
p Rhs ()
rhs (if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Decl ()]
ds then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just ([Decl ()] -> Binds ()
binds [Decl ()]
ds))
nameBind :: Name () -> Exp () -> Decl ()
nameBind :: Name () -> Exp () -> Decl ()
nameBind Name ()
n Exp ()
e = Pat () -> Exp () -> Decl ()
patBind (Name () -> Pat ()
pvar Name ()
n) Exp ()
e
metaFunction :: String -> [Exp ()] -> Exp ()
metaFunction :: String -> [Exp ()] -> Exp ()
metaFunction String
s' [Exp ()]
es' = String -> [Exp ()] -> Exp ()
mf String
s' (forall a. [a] -> [a]
reverse [Exp ()]
es')
where mf :: String -> [Exp ()] -> Exp ()
mf String
s [] = Name () -> Exp ()
var forall a b. (a -> b) -> a -> b
$ String -> Name ()
name String
s
mf String
s (Exp ()
e:[Exp ()]
es) = Exp () -> Exp () -> Exp ()
app (String -> [Exp ()] -> Exp ()
mf String
s [Exp ()]
es) Exp ()
e
metaConPat :: String -> [Pat ()] -> Pat ()
metaConPat :: String -> [Pat ()] -> Pat ()
metaConPat String
s [Pat ()]
ps = Name () -> [Pat ()] -> Pat ()
pApp (String -> Name ()
name String
s) [Pat ()]
ps