-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A compiler for Fay, a Haskell subset that compiles to JavaScript. -- -- Fay is a proper subset of Haskell which can be compiled (type-checked) -- with GHC, and compiled to JavaScript. It is lazy, pure, with a Fay -- monad, an FFI, tail-recursion optimization (experimental). It -- implements no type system, for type-checking you should use GHC. -- -- Documentation -- -- See documentation at http://fay-lang.org/ or build your own -- documentation with: -- --
-- $ cabal unpack fay -- $ cd fay-* -- $ cabal install -- $ dist/build/fay-docs/fay-docs ---- -- Examples -- -- See http://fay-lang.org/#examples. -- -- Release Notes -- -- Some more compilation options. -- --
-- infixr 5 :^: -- data Tree a = Leaf a | Tree a :^: Tree a ---- -- the derived instance of Show is equivalent to -- --
-- instance (Show a) => Show (Tree a) where -- -- showsPrec d (Leaf m) = showParen (d > app_prec) $ -- showString "Leaf " . showsPrec (app_prec+1) m -- where app_prec = 10 -- -- showsPrec d (u :^: v) = showParen (d > up_prec) $ -- showsPrec (up_prec+1) u . -- showString " :^: " . -- showsPrec (up_prec+1) v -- where up_prec = 5 ---- -- Note that right-associativity of :^: is ignored. For example, -- --
-- infixr 5 :^: -- data Tree a = Leaf a | Tree a :^: Tree a ---- -- the derived instance of Read in Haskell 98 is equivalent to -- --
-- instance (Read a) => Read (Tree a) where
--
-- readsPrec d r = readParen (d > app_prec)
-- (\r -> [(Leaf m,t) |
-- ("Leaf",s) <- lex r,
-- (m,t) <- readsPrec (app_prec+1) s]) r
--
-- ++ readParen (d > up_prec)
-- (\r -> [(u:^:v,w) |
-- (u,s) <- readsPrec (up_prec+1) r,
-- (":^:",t) <- lex s,
-- (v,w) <- readsPrec (up_prec+1) t]) r
--
-- where app_prec = 10
-- up_prec = 5
--
--
-- Note that right-associativity of :^: is unused.
--
-- The derived instance in GHC is equivalent to
--
-- -- instance (Read a) => Read (Tree a) where -- -- readPrec = parens $ (prec app_prec $ do -- Ident "Leaf" <- lexP -- m <- step readPrec -- return (Leaf m)) -- -- +++ (prec up_prec $ do -- u <- step readPrec -- Symbol ":^:" <- lexP -- v <- step readPrec -- return (u :^: v)) -- -- where app_prec = 10 -- up_prec = 5 -- -- readListPrec = readListPrecDefault --class Read a -- | The Maybe type encapsulates an optional value. A value of type -- Maybe a either contains a value of type a -- (represented as Just a), or it is empty (represented -- as Nothing). Using Maybe is a good way to deal with -- errors or exceptional cases without resorting to drastic measures such -- as error. -- -- The Maybe type is also a monad. It is a simple kind of error -- monad, where all errors are represented by Nothing. A richer -- error monad can be built using the Either type. data Maybe a :: * -> * Nothing :: Maybe a Just :: a -> Maybe a -- | The read function reads input from a string, which must be -- completely consumed by the input process. read :: Read a => String -> a -- | Just to satisfy GHC. fromInteger :: Integer -> Double -- | Just to satisfy GHC. fromRational :: Ratio Integer -> Double (>>) :: Fay a -> Fay b -> Fay b (>>=) :: Fay a -> (a -> Fay b) -> Fay b (==) :: Eq a => a -> a -> Bool (/=) :: Eq a => a -> a -> Bool (+) :: Num a => a -> a -> a (*) :: Num a => a -> a -> a (-) :: Num a => a -> a -> a (>) :: Ord a => a -> a -> Bool (<) :: Ord a => a -> a -> Bool (>=) :: Ord a => a -> a -> Bool (<=) :: Ord a => a -> a -> Bool -- | fractional division (/) :: Fractional a => a -> a -> a -- | Boolean "or" (||) :: Bool -> Bool -> Bool -- | Boolean "and" (&&) :: Bool -> Bool -> Bool fail :: String -> Fay a return :: a -> Fay a ($) :: (t1 -> t) -> t1 -> t snd :: (t, t1) -> t1 fst :: (t, t1) -> t find :: (a -> Bool) -> [a] -> Maybe a any :: (t -> Bool) -> [t] -> Bool filter :: (a -> Bool) -> [a] -> [a] not :: Bool -> Bool null :: [t] -> Bool map :: (a -> b) -> [a] -> [b] nub :: Eq a => [a] -> [a] elem :: Eq a => a -> [a] -> Bool data Ordering GT :: Ordering LT :: Ordering EQ :: Ordering sort :: Ord a => [a] -> [a] compare :: Ord a => a -> a -> Ordering sortBy :: (t -> t -> Ordering) -> [t] -> [t] insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a] enumFrom :: Num a => a -> [a] zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] zip :: [a] -> [b] -> [(a, b)] flip :: (t1 -> t2 -> t) -> t2 -> t1 -> t maybe :: t -> (t1 -> t) -> Maybe t1 -> t (.) :: (t1 -> t) -> (t2 -> t1) -> t2 -> t (++) :: [a] -> [a] -> [a] concat :: [[a]] -> [a] foldr :: (t -> t1 -> t1) -> t1 -> [t] -> t1 foldl :: (t1 -> t -> t1) -> t1 -> [t] -> t1 lookup :: Eq a1 => a1 -> [(a1, a)] -> Maybe a intersperse :: a -> [a] -> [a] prependToAll :: a -> [a] -> [a] intercalate :: [a] -> [[a]] -> [a] forM_ :: Monad m => [t] -> (t -> m a) -> m () -- | The Haskell→Javascript compiler. module Language.Fay -- | Compile something that compiles to something else. compile :: CompilesTo from to => CompileConfig -> from -> IO (Either CompileError (to, CompileState)) -- | Run the compiler. runCompile :: CompileConfig -> Compile a -> IO (Either CompileError (a, CompileState)) -- | Compile a Haskell source string to a JavaScript source string. compileViaStr :: (Show from, Show to, CompilesTo from to) => CompileConfig -> (from -> Compile to) -> String -> IO (Either CompileError (String, CompileState)) -- | Compile a Haskell source string to a JavaScript source string. compileToAst :: (Show from, Show to, CompilesTo from to) => CompileConfig -> (from -> Compile to) -> String -> IO (Either CompileError (to, CompileState)) -- | Compile from a string. compileFromStr :: (Parseable a, MonadError CompileError m) => (a -> m a1) -> String -> m a1 printCompile :: (Show from, Show to, CompilesTo from to) => CompileConfig -> (from -> Compile to) -> String -> IO () -- | Compile Haskell module. compileModule :: Module -> Compile [JsStmt] -- | Compile the given import. compileImport :: ImportDecl -> Compile [JsStmt] -- | Compile Haskell declaration. compileDecls :: [Decl] -> Compile [JsStmt] -- | Compile a declaration. compileDecl :: Decl -> Compile [JsStmt] -- | Compile a top-level pattern bind. compilePatBind :: Maybe Type -> Decl -> Compile [JsStmt] -- | Compile a normal simple pattern binding. compileNormalPatBind :: Name -> Exp -> Compile [JsStmt] -- | Compile a foreign function. compileFFIFunc :: Type -> Name -> (String, String, FayReturnType) -> Compile [JsStmt] -- | Compile a foreign method. compileFFIMethod :: Type -> Name -> (String, String, FayReturnType) -> Compile [JsStmt] -- | Compile a foreign method. compileFFISetProp :: Type -> Name -> (String, String, FayReturnType) -> Compile [JsStmt] -- | Compile an FFI call. compileFFI :: Type -> Name -> (String, String, FayReturnType) -> JsExp -> [JsName] -> [JsName] -> Compile [JsStmt] -- | These are the data types that are serializable directly to native JS -- data types. Strings, floating points and arrays. The others are: -- actiosn in the JS monad, which are thunks that shouldn't be forced -- when serialized but wrapped up as JS zero-arg functions, and unknown -- types can't be converted but should at least be forced. data ArgType FunctionType :: ArgType JsType :: ArgType StringType :: ArgType DoubleType :: ArgType ListType :: ArgType BoolType :: ArgType UnknownType :: ArgType -- | Serialize a value to native JS, if possible. serialize :: ArgType -> JsExp -> JsExp -- | Get arg types of a function type. functionTypeArgs :: Type -> [ArgType] -- | Get the arity of a type. typeArity :: Type -> Integer -- | Compile a data declaration. compileDataDecl :: Decl -> [QualConDecl] -> Compile [JsStmt] -- | Extract the string from a qname. qname :: QName -> String -- | Extra the string from an ident. unname :: Name -> String -- | Compile a function which pattern matches (causing a case analysis). compileFunCase :: [Match] -> Compile [JsStmt] -- | Optimize functions in tail-call form. optimizeTailCalls :: [JsParam] -> Name -> [JsStmt] -> [JsStmt] -- | Flatten an application expression into function : arg : arg : [] flatten :: JsExp -> Maybe [JsExp] -- | Expand a forced value into the value. expand :: JsExp -> Maybe [JsExp] prettyPrintFile :: String -> IO String -- | Compile a right-hand-side expression. compileRhs :: Rhs -> Compile JsExp -- | Compile a pattern match binding. compileFunMatch :: Match -> Compile [JsStmt] -- | Compile Haskell expression. compileExp :: Exp -> Compile JsExp -- | Compile simple application. compileApp :: Exp -> Exp -> Compile JsExp -- | Compile an infix application, optimizing the JS cases. compileInfixApp :: Exp -> QOp -> Exp -> Compile JsExp -- | Compile a list expression. compileList :: [Exp] -> Compile JsExp -- | Compile an if. compileIf :: Exp -> Exp -> Exp -> Compile JsExp -- | Compile a lambda. compileLambda :: [Pat] -> Exp -> Compile JsExp -- | Compile case expressions. compileCase :: Exp -> [Alt] -> Compile JsExp -- | Compile a do block. compileDoBlock :: [Stmt] -> Compile JsExp -- | Compile a statement of a do block. compileStmt :: Maybe Exp -> Stmt -> Compile (Maybe Exp) -- | Compile the given pattern against the given expression. compilePatAlt :: JsExp -> Alt -> Compile [JsStmt] -- | Compile the given pattern against the given expression. compilePat :: JsExp -> Pat -> [JsStmt] -> Compile [JsStmt] -- | Compile a literal value from a pattern match. compilePLit :: JsExp -> Literal -> [JsStmt] -> Compile [JsStmt] -- | Equality test for two expressions, with some optimizations. equalExps :: JsExp -> JsExp -> JsExp -- | Is a JS expression a literal (constant)? isConstant :: JsExp -> Bool -- | Compile a pattern application. compilePApp :: QName -> [Pat] -> JsExp -> [JsStmt] -> Compile [JsStmt] -- | Compile a pattern list. compilePList :: [Pat] -> [JsStmt] -> JsExp -> Compile [JsStmt] -- | Compile an infix pattern (e.g. cons and tuples.) compileInfixPat :: JsExp -> Pat -> [JsStmt] -> Compile [JsStmt] -- | Compile a guarded alt. compileGuardedAlt :: GuardedAlts -> Compile JsExp -- | Compile a let expression. compileLet :: [Decl] -> Exp -> Compile JsExp -- | Compile let declaration. compileLetDecl :: Decl -> Compile [JsStmt] -- | Compile Haskell literal. compileLit :: Literal -> Compile JsExp -- | Generate unique names. uniqueNames :: [JsParam] -- | Optimize pattern matching conditions by merging conditions in common. optimizePatConditions :: [[JsStmt]] -> [[JsStmt]] -- | Throw a JS exception. throw :: String -> JsExp -> JsStmt -- | Throw a JS exception (in an expression). throwExp :: String -> JsExp -> JsExp -- | Is an alt a wildcard? isWildCardAlt :: Alt -> Bool -- | Is a pattern a wildcard? isWildCardPat :: Pat -> Bool -- | A temporary name for testing conditions and such. tmpName :: JsExp -> JsName -- | Wrap an expression in a thunk. thunk :: JsExp -> JsExp -- | Wrap an expression in a thunk. monad :: JsExp -> JsExp -- | Wrap an expression in a thunk. stmtsThunk :: [JsStmt] -> JsExp unserialize :: FayReturnType -> JsExp -> JsExp -- | Force an expression in a thunk. force :: JsExp -> JsExp -- | Force an expression in a thunk. forceInlinable :: CompileConfig -> JsExp -> JsExp -- | Resolve operators to only built-in (for now) functions. resolveOpToVar :: QOp -> Compile Exp -- | Make an identifier from the built-in HJ module. hjIdent :: String -> QName -- | Make a top-level binding. bindToplevel :: QName -> JsExp -> Compile JsStmt -- | Emit exported names. emitExport :: ExportSpec -> Compile () -- | Parse result. parseResult :: ((SrcLoc, String) -> b) -> (a -> b) -> ParseResult a -> b -- | Get a config option. config :: (CompileConfig -> a) -> Compile a instance Show ArgType instance Eq ArgType instance CompilesTo Exp JsExp instance CompilesTo Decl [JsStmt] instance CompilesTo Module [JsStmt]