-- 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 is type-checked with GHC, and -- compiled to JavaScript. It is lazy, pure, has a Fay monad, an FFI, -- tail-recursion optimization (experimental), and support for cabal -- packages. -- -- Documentation -- -- See documentation at http://fay-lang.org/ or build your own -- documentation with: -- --
--   $ cabal unpack fay
--   $ cd fay-*
--   $ cabal install
--   $ cabal install fay-base
--   
-- -- Examples -- -- See http://fay-lang.org/#examples. -- -- Release Notes -- -- -- -- See full history at: https://github.com/faylang/fay/commits @package fay @version 0.14.2.0 -- | Convert a Haskell value to a (JSON representation of a) Fay value. module Fay.Convert -- | Convert a Haskell value to a value representing a Fay value. showToFay :: Show a => a -> Maybe Value -- | Convert a value representing a Fay value to a Haskell value. readFromFay :: Data a => Value -> Maybe a -- | All Fay types and instances. module Fay.Types -- | Statement type. data JsStmt JsVar :: JsName -> JsExp -> JsStmt JsMappedVar :: SrcLoc -> 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 JsSetPropExtern :: JsName -> JsName -> JsExp -> JsStmt JsContinue :: JsStmt JsBlock :: [JsStmt] -> JsStmt JsExpStmt :: JsExp -> JsStmt -- | Expression type. data JsExp JsName :: JsName -> JsExp JsRawExp :: String -> JsExp JsSeq :: [JsExp] -> JsExp JsFun :: [JsName] -> [JsStmt] -> (Maybe JsExp) -> JsExp JsLit :: JsLit -> JsExp JsApp :: JsExp -> [JsExp] -> JsExp JsNegApp :: JsExp -> JsExp JsTernaryIf :: JsExp -> JsExp -> JsExp -> JsExp JsNull :: JsExp JsParen :: JsExp -> JsExp JsGetProp :: JsExp -> JsName -> JsExp JsLookup :: JsExp -> JsExp -> JsExp JsUpdateProp :: JsExp -> JsName -> JsExp -> JsExp JsGetPropExtern :: JsExp -> String -> JsExp JsUpdatePropExtern :: 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 JsNeq :: JsExp -> JsExp -> JsExp JsInfix :: String -> JsExp -> JsExp -> JsExp JsObj :: [(String, JsExp)] -> JsExp JsUndefined :: JsExp -- | Literal value type. data JsLit JsChar :: Char -> JsLit JsStr :: String -> JsLit JsInt :: Int -> JsLit JsFloating :: Double -> JsLit JsBool :: Bool -> JsLit -- | A name of some kind. data JsName JsNameVar :: QName -> JsName JsThis :: JsName JsParametrizedType :: JsName JsThunk :: JsName JsForce :: JsName JsApply :: JsName JsParam :: Integer -> JsName JsTmp :: Integer -> JsName JsConstructor :: QName -> JsName JsBuiltIn :: Name -> JsName -- | 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 UnsupportedFieldPattern :: PatField -> CompileError UnsupportedRhs :: Rhs -> CompileError UnsupportedGuardedAlts :: GuardedAlts -> CompileError UnsupportedWhereInAlt :: Alt -> CompileError UnsupportedImport :: ImportDecl -> CompileError UnsupportedQualStmt :: QualStmt -> CompileError EmptyDoBlock :: CompileError UnsupportedModuleSyntax :: Module -> CompileError LetUnsupported :: CompileError InvalidDoBlock :: CompileError RecursiveDoUnsupported :: CompileError Couldn'tFindImport :: ModuleName -> [FilePath] -> CompileError FfiNeedsTypeSig :: Decl -> CompileError FfiFormatBadChars :: SrcLoc -> String -> CompileError FfiFormatNoSuchArg :: SrcLoc -> Int -> CompileError FfiFormatIncompleteArg :: SrcLoc -> CompileError FfiFormatInvalidJavaScript :: SrcLoc -> String -> String -> CompileError UnableResolveUnqualified :: Name -> CompileError UnableResolveQualified :: QName -> CompileError -- | Compile monad. newtype Compile a Compile :: RWST CompileReader CompileWriter CompileState (ErrorT CompileError IO) a -> Compile a -- | Run the compiler. unCompile :: Compile a -> RWST CompileReader CompileWriter 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 -> Printer () -- | The JavaScript FFI interfacing monad. data Fay a -- | Configuration and globals for the compiler. data CompileReader CompileReader :: CompileConfig -> (Literal -> Compile JsExp) -> (Bool -> [Decl] -> Compile [JsStmt]) -> CompileReader -- | The compilation configuration. readerConfig :: CompileReader -> CompileConfig readerCompileLit :: CompileReader -> Literal -> Compile JsExp readerCompileDecls :: CompileReader -> Bool -> [Decl] -> Compile [JsStmt] -- | Things written out by the compiler. data CompileWriter CompileWriter :: [JsStmt] -> [JsStmt] -> [JsStmt] -> CompileWriter -- | Constructors. writerCons :: CompileWriter -> [JsStmt] -- | Fay to JS dispatchers. writerFayToJs :: CompileWriter -> [JsStmt] -- | JS to Fay dispatchers. writerJsToFay :: CompileWriter -> [JsStmt] -- | Configuration of the compiler. data CompileConfig CompileConfig :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> [(Maybe String, FilePath)] -> Bool -> Bool -> [FilePath] -> Bool -> Bool -> Maybe FilePath -> Bool -> Bool -> Bool -> Maybe FilePath -> [String] -> CompileConfig -- | Run optimizations configOptimize :: CompileConfig -> Bool -- | Flatten function application? configFlattenApps :: CompileConfig -> Bool -- | Export built-in functions? configExportBuiltins :: CompileConfig -> Bool -- | Export the runtime? configExportRuntime :: CompileConfig -> Bool -- | Export the stdlib? configExportStdlib :: CompileConfig -> Bool -- | Export only the stdlib? configExportStdlibOnly :: CompileConfig -> Bool -- | Export dispatchers? configDispatchers :: CompileConfig -> Bool -- | Export only the dispatcher? configDispatcherOnly :: CompileConfig -> Bool -- | Export without a module wrapper? configNaked :: CompileConfig -> Bool -- | Possibly a fay package name, and a include directory. configDirectoryIncludes :: CompileConfig -> [(Maybe String, FilePath)] -- | Pretty print the JS output? configPrettyPrint :: CompileConfig -> Bool -- | Output a HTML file including the produced JS. configHtmlWrapper :: CompileConfig -> Bool -- | Any JS files to link to in the HTML. configHtmlJSLibs :: CompileConfig -> [FilePath] -- | Don't invoke main in the produced JS. configLibrary :: CompileConfig -> Bool -- | Warn on dubious stuff, not related to typechecking. configWarn :: CompileConfig -> Bool -- | File path to output to. TODO: This flag is not used thoroughly, decide -- if it's needed. configFilePath :: CompileConfig -> Maybe FilePath -- | Typecheck with GHC. configTypecheck :: CompileConfig -> Bool -- | Typecheck with -Wall. configWall :: CompileConfig -> Bool -- | Run Google Closure on the produced JS. configGClosure :: CompileConfig -> Bool -- | The package config e.g. packages-6.12.3. configPackageConf :: CompileConfig -> Maybe FilePath -- | Included Fay packages. configPackages :: CompileConfig -> [String] -- | State of the compiler. data CompileState CompileState :: Map ModuleName (Set QName) -> [(QName, [QName])] -> [(QName, [QName])] -> [(ModuleName, FilePath)] -> Integer -> Set Name -> ModuleScope -> ModuleName -> CompileState -- | Collects exports from modules _stateExports :: CompileState -> Map ModuleName (Set QName) -- | Map types to constructors stateRecordTypes :: CompileState -> [(QName, [QName])] -- | Map constructors to fields stateRecords :: CompileState -> [(QName, [QName])] -- | Map of all imported modules and their source locations. stateImported :: CompileState -> [(ModuleName, FilePath)] -- | Depth of the current lexical scope. stateNameDepth :: CompileState -> Integer -- | Names in the current lexical scope. stateLocalScope :: CompileState -> Set Name -- | Names in the module scope. stateModuleScope :: CompileState -> ModuleScope -- | Name of the module currently being compiled. stateModuleName :: CompileState -> ModuleName -- | Adds a new export to _stateExports for the module specified by -- stateModuleName. addCurrentExport :: QName -> CompileState -> CompileState -- | Get all of the exported identifiers for the current module. getCurrentExports :: CompileState -> Set QName -- | Get all of the exported identifiers for the given module. getExportsFor :: ModuleName -> CompileState -> Set QName -- | The data-files source directory. faySourceDir :: IO FilePath -- | These are the data types that are serializable directly to native JS -- data types. Strings, floating points and arrays. The others are: -- actions 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 FundamentalType FunctionType :: [FundamentalType] -> FundamentalType JsType :: FundamentalType -> FundamentalType ListType :: FundamentalType -> FundamentalType TupleType :: [FundamentalType] -> FundamentalType UserDefined :: Name -> [FundamentalType] -> FundamentalType Defined :: FundamentalType -> FundamentalType Nullable :: FundamentalType -> FundamentalType DateType :: FundamentalType StringType :: FundamentalType DoubleType :: FundamentalType IntType :: FundamentalType BoolType :: FundamentalType PtrType :: FundamentalType Automatic :: FundamentalType UnknownType :: FundamentalType -- | The state of the pretty printer. data PrintState PrintState :: Bool -> Int -> Int -> [Mapping] -> Int -> [String] -> Bool -> PrintState -- | Are we to pretty print? psPretty :: PrintState -> Bool -- | The current line. psLine :: PrintState -> Int -- | Current column. psColumn :: PrintState -> Int -- | Source mappings. psMapping :: PrintState -> [Mapping] -- | Current indentation level. psIndentLevel :: PrintState -> Int -- | The current output. TODO: Make more efficient. psOutput :: PrintState -> [String] -- | Just outputted a newline? psNewline :: PrintState -> Bool -- | The printer monad. newtype Printer a Printer :: State PrintState a -> Printer a runPrinter :: Printer a -> State PrintState a -- | A source mapping. data Mapping Mapping :: String -> SrcLoc -> SrcLoc -> Mapping -- | The name of the mapping. mappingName :: Mapping -> String -- | The original source location. mappingFrom :: Mapping -> SrcLoc -- | The new source location. mappingTo :: Mapping -> SrcLoc -- | The serialization context indicates whether we're currently -- serializing some value or a particular field in a user-defined data -- type. data SerializeContext SerializeAnywhere :: SerializeContext SerializeUserArg :: Int -> SerializeContext instance Show CompileConfig instance Show CompileState instance Show Mapping instance Monad Printer instance Functor Printer instance MonadState PrintState Printer instance Show CompileError instance Monad Fay instance Eq JsName instance Show JsName instance Show JsLit instance Eq JsLit instance Show JsExp instance Eq JsExp instance Show JsStmt instance Eq JsStmt instance Show CompileWriter instance MonadState CompileState Compile instance MonadError CompileError Compile instance MonadReader CompileReader Compile instance MonadWriter CompileWriter Compile instance MonadIO Compile instance Monad Compile instance Functor Compile instance Applicative Compile instance Show FundamentalType instance Read SerializeContext instance Show SerializeContext instance Eq SerializeContext instance IsString ModuleName instance IsString QName instance IsString Name instance IsString JsLit instance Error CompileError instance Default PrintState instance Monoid CompileWriter -- | The internal FFI module. Needs to be renamed to Fay.FFI at some point. module Language.Fay.FFI -- | The JavaScript FFI interfacing monad. data Fay a -- | Values that may be null Nullable x decodes to x, Null decodes to null. data Nullable a Nullable :: a -> Nullable a Null :: Nullable a -- | Values that may be undefined Defined x encodes to x, Undefined decodes -- to undefined. An undefined property in a record will be removed when -- encoding. data Defined a Defined :: a -> Defined a Undefined :: Defined a -- | Do not serialize the specified type. This is useful for, e.g. -- --
--   foo :: String -> String
--   foo = ffi "%1"
--   
-- -- This would normally serialize and unserialize the string, for no -- reason, in this case. Instead: -- --
--   foo :: Ptr String -> Ptr String
--   
-- -- Will just give an identity function. type Ptr a = a -- | The opposite of Ptr. Serialize the specified polymorphic type. -- --
--   foo :: Automatic a -> String
--   
type Automatic a = a -- | Declare a foreign action. ffi :: String -> a -- | Configuration functions. module Fay.Compiler.Config -- | Get all include directories without the package mapping. configDirectoryIncludePaths :: CompileConfig -> [FilePath] -- | Get all include directories not included through packages. nonPackageConfigDirectoryIncludePaths :: CompileConfig -> [FilePath] -- | Add a mapping from (maybe) a package to a source directory addConfigDirectoryInclude :: Maybe String -> FilePath -> CompileConfig -> CompileConfig -- | Add several include directories. addConfigDirectoryIncludes :: [(Maybe String, FilePath)] -> CompileConfig -> CompileConfig -- | Add several include directories without package references. addConfigDirectoryIncludePaths :: [FilePath] -> CompileConfig -> CompileConfig -- | Add a package to compilation addConfigPackage :: String -> CompileConfig -> CompileConfig -- | Add several packages to compilation addConfigPackages :: [String] -> CompileConfig -> CompileConfig instance Default CompileConfig -- | The Haskell→Javascript compiler. module Fay.Compiler -- | Run the compiler. runCompile :: CompileReader -> CompileState -> Compile a -> IO (Either CompileError (a, CompileState, CompileWriter)) -- | Compile a Haskell source string to a JavaScript source string. compileViaStr :: (Show from, Show to, CompilesTo from to) => FilePath -> CompileConfig -> (from -> Compile to) -> String -> IO (Either CompileError (PrintState, CompileState, CompileWriter)) -- | Compile the given Fay code for the documentation. This is specialised -- because the documentation isn't really “real” compilation. compileForDocs :: Module -> Compile [JsStmt] -- | Compile a Haskell source string to a JavaScript source string. compileToAst :: (Show from, Show to, CompilesTo from to) => FilePath -> CompileReader -> CompileState -> (from -> Compile to) -> String -> IO (Either CompileError (to, CompileState, CompileWriter)) -- | Compile Haskell module. compileModule :: Bool -> Module -> Compile [JsStmt] -- | Compile Haskell expression. compileExp :: Exp -> Compile JsExp -- | Compile a declaration. compileDecl :: Bool -> Decl -> Compile [JsStmt] -- | Compile the top-level Fay module. compileToplevelModule :: Module -> Compile [JsStmt] -- | Parse some Fay code. parseFay :: Parseable ast => FilePath -> String -> ParseResult ast instance CompilesTo Module [JsStmt] -- | Some useful debug functions. module Fay.Compiler.Debug -- | Compile a String of Fay and print it as beautified JavaScript. printTestCompile :: String -> IO () -- | Compile a Haskell source string to a JavaScript source string. compileTestAst :: (Show from, Show to, CompilesTo from to) => CompileConfig -> (from -> Compile to) -> String -> IO () -- | Print a useful debug output of a compilation. debug :: (Show from, Show to, CompilesTo from to) => (from -> Compile to) -> String -> IO () -- | Compile the given input and print the output out prettily. printCompile :: (Show from, Show to, CompilesTo from to) => CompileConfig -> (from -> Compile to) -> String -> IO () -- | Main library entry point. module Fay -- | Compile the given file. compileFile :: CompileConfig -> FilePath -> IO (Either CompileError String) -- | Compile a file returning the state. compileFileWithState :: CompileConfig -> FilePath -> IO (Either CompileError (String, CompileState)) -- | Compile the given file and write the output to the given path, or if -- nothing given, stdout. compileFromTo :: CompileConfig -> FilePath -> Maybe FilePath -> IO () -- | Compile the given file and write to the output, also generate any -- HTML. compileFromToAndGenerateHtml :: CompileConfig -> FilePath -> FilePath -> IO (Either CompileError String) -- | Convert a Haskell filename to a JS filename. toJsName :: String -> String -- | Print a compile error for human consumption. showCompileError :: CompileError -> String -- | Get the JS runtime source. getRuntime :: IO String