-- 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. -- -- -- -- See full history at: https://github.com/chrisdone/fay/commits @package fay @version 0.2.2.0 -- | Convert a Haskell value to a Fay value. module Language.Fay.Show -- | Convert a Haskell value to a Fay value. To read this in from JS, use -- Fay.eval() which will evaluate the code in the context of Fay. showToFay :: Show a => a -> String -- | All Fay types and instances. module Language.Fay.Types -- | Statement type. data JsStmt JsVar :: JsName -> JsExp -> JsStmt JsIf :: JsExp -> [JsStmt] -> [JsStmt] -> JsStmt JsEarlyReturn :: JsExp -> JsStmt JsThrow :: JsExp -> JsStmt JsWhile :: JsExp -> [JsStmt] -> JsStmt JsUpdate :: JsName -> JsExp -> JsStmt JsSetProp :: JsName -> JsName -> JsExp -> JsStmt JsContinue :: JsStmt -- | Expression type. data JsExp JsName :: JsName -> JsExp JsRawName :: String -> JsExp JsFun :: [JsParam] -> [JsStmt] -> (Maybe JsExp) -> JsExp JsLit :: JsLit -> JsExp JsApp :: JsExp -> [JsExp] -> JsExp JsTernaryIf :: JsExp -> JsExp -> JsExp -> JsExp JsNull :: JsExp JsSequence :: [JsExp] -> JsExp JsParen :: JsExp -> JsExp JsGetProp :: JsExp -> JsName -> JsExp JsUpdateProp :: JsExp -> JsName -> JsExp -> JsExp JsList :: [JsExp] -> JsExp JsNew :: JsName -> [JsExp] -> JsExp JsThrowExp :: JsExp -> JsExp JsInstanceOf :: JsExp -> JsName -> JsExp JsIndex :: Int -> JsExp -> JsExp JsEq :: JsExp -> JsExp -> JsExp JsInfix :: String -> JsExp -> JsExp -> JsExp -- | Literal value type. data JsLit JsChar :: Char -> JsLit JsStr :: String -> JsLit JsInt :: Int -> JsLit JsFloating :: Double -> JsLit JsBool :: Bool -> JsLit -- | Convenience type for function parameters. type JsParam = JsName -- | To be used to force name sanitization eventually. type JsName = QName -- | Error type. data CompileError ParseError :: SrcLoc -> String -> CompileError UnsupportedDeclaration :: Decl -> CompileError UnsupportedExportSpec :: ExportSpec -> CompileError UnsupportedMatchSyntax :: Match -> CompileError UnsupportedWhereInMatch :: Match -> CompileError UnsupportedExpression :: Exp -> CompileError UnsupportedLiteral :: Literal -> CompileError UnsupportedLetBinding :: Decl -> CompileError UnsupportedOperator :: QOp -> CompileError UnsupportedPattern :: Pat -> CompileError UnsupportedRhs :: Rhs -> CompileError UnsupportedGuardedAlts :: GuardedAlts -> CompileError EmptyDoBlock :: CompileError UnsupportedModuleSyntax :: Module -> CompileError LetUnsupported :: CompileError InvalidDoBlock :: CompileError RecursiveDoUnsupported :: CompileError FfiNeedsTypeSig :: Decl -> CompileError -- | Compile monad. newtype Compile a Compile :: StateT CompileState (ErrorT CompileError IO) a -> Compile a unCompile :: Compile a -> StateT CompileState (ErrorT CompileError IO) a -- | Just a convenience class to generalize the parsing/printing of various -- types of syntax. class (Parseable from, Printable to) => CompilesTo from to | from -> to compileTo :: CompilesTo from to => from -> Compile to -- | Print some value. class Printable a printJS :: Printable a => a -> String -- | The JavaScript FFI interfacing monad. data Fay a -- | Configuration of the compiler. data CompileConfig CompileConfig :: Bool -> Bool -> Bool -> Bool -> CompileConfig configTCO :: CompileConfig -> Bool configInlineForce :: CompileConfig -> Bool configFlattenApps :: CompileConfig -> Bool configExportBuiltins :: CompileConfig -> Bool -- | State of the compiler. data CompileState CompileState :: CompileConfig -> [Name] -> Bool -> ModuleName -> CompileState stateConfig :: CompileState -> CompileConfig stateExports :: CompileState -> [Name] stateExportAll :: CompileState -> Bool stateModuleName :: CompileState -> ModuleName data FayReturnType FayArray :: FayReturnType FayList :: FayReturnType FayString :: FayReturnType FayNone :: FayReturnType instance Typeable CompileError instance Show CompileConfig instance Show CompileState instance Show CompileError instance Eq CompileError instance Data CompileError instance MonadState CompileState Compile instance MonadError CompileError Compile instance MonadIO Compile instance Monad Compile instance Functor Compile instance Applicative Compile instance Monad Fay instance Show JsLit instance Eq JsLit instance Show JsExp instance Eq JsExp instance Show JsStmt instance Eq JsStmt instance Read FayReturnType instance Show FayReturnType instance Eq FayReturnType instance Exception CompileError instance Error CompileError instance Default CompileConfig module Language.Fay.FFI data JsPtr a -- | Contains allowed foreign function types. class Foreign a -- | Declare a foreign action. foreignFay :: Foreign a => String -> FayReturnType -> a -- | Declare a foreign function. foreignPure :: Foreign a => String -> FayReturnType -> a -- | Declare a foreign action. foreignPropFay :: Foreign a => String -> FayReturnType -> a -- | Declare a foreign function. foreignProp :: Foreign a => String -> FayReturnType -> a -- | Declare a foreign action. foreignSetProp :: (Foreign object, Foreign value) => String -> object -> value -> Fay () instance (Foreign a, Foreign b) => Foreign (a -> b) instance Foreign a => Foreign (Fay a) instance Foreign (JsPtr a) instance Foreign a => Foreign [a] instance Foreign Bool instance Foreign Char instance Foreign Double instance Foreign () module Language.Fay.Prelude -- | The JavaScript FFI interfacing monad. data Fay a data FayReturnType FayArray :: FayReturnType FayList :: FayReturnType FayString :: FayReturnType FayNone :: FayReturnType -- | The character type Char is an enumeration whose values -- represent Unicode (or equivalently ISO/IEC 10646) characters (see -- http://www.unicode.org/ for details). This set extends the ISO -- 8859-1 (Latin-1) character set (the first 256 characters), which is -- itself an extension of the ASCII character set (the first 128 -- characters). A character literal in Haskell has type Char. -- -- To convert a Char to or from the corresponding Int value -- defined by Unicode, use toEnum and fromEnum from the -- Enum class respectively (or equivalently ord and -- chr). data Char :: * -- | A String is a list of characters. String constants in Haskell -- are values of type String. type String = [Char] -- | Arbitrary-precision integers. data Integer :: * -- | Double-precision floating point numbers. It is desirable that this -- type be at least equal in range and precision to the IEEE -- double-precision type. data Double :: * data Bool :: * False :: Bool True :: Bool -- | Conversion of values to readable Strings. -- -- Minimal complete definition: showsPrec or show. -- -- Derived instances of Show have the following properties, which -- are compatible with derived instances of Read: -- -- -- -- For example, given the declarations -- --
--   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, -- -- class Show a show :: Show a => a -> String -- | Parsing of Strings, producing values. -- -- Minimal complete definition: readsPrec (or, for GHC only, -- readPrec) -- -- Derived instances of Read make the following assumptions, which -- derived instances of Show obey: -- -- -- -- For example, given the declarations -- --
--   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]