-- 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 http://fay-lang.org/ -- -- Examples -- -- See the examples directory and -- https://github.com/faylang/fay/wiki#fay-in-the-wild -- -- Release Notes -- -- See https://github.com/faylang/fay/wiki/Changelog -- -- See full history at: -- https://github.com/faylang/fay/wiki/Changelog @package fay @version 0.16.0.2 -- | 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 JsSetQName :: QName -> JsExp -> JsStmt JsSetModule :: ModulePath -> JsExp -> JsStmt JsSetConstructor :: QName -> 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 :: (Maybe JsName) -> [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 JsLitObj :: [(Name, JsExp)] -> JsExp JsUndefined :: JsExp JsAnd :: JsExp -> JsExp -> JsExp JsOr :: JsExp -> JsExp -> 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 JsModuleName :: ModuleName -> JsName -- | Error type. data CompileError ParseError :: SrcLoc -> String -> CompileError UnsupportedDeclaration :: Decl -> CompileError UnsupportedExportSpec :: ExportSpec -> CompileError UnsupportedExpression :: Exp -> CompileError UnsupportedFieldPattern :: PatField -> CompileError UnsupportedImport :: ImportDecl -> CompileError UnsupportedLet :: CompileError UnsupportedLetBinding :: Decl -> CompileError UnsupportedLiteral :: Literal -> CompileError UnsupportedModuleSyntax :: Module -> CompileError UnsupportedPattern :: Pat -> CompileError UnsupportedQualStmt :: QualStmt -> CompileError UnsupportedRecursiveDo :: CompileError UnsupportedRhs :: Rhs -> CompileError UnsupportedWhereInAlt :: Alt -> CompileError UnsupportedWhereInMatch :: Match -> CompileError EmptyDoBlock :: CompileError InvalidDoBlock :: 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 UnableResolveQualified :: QName -> CompileError GHCError :: String -> 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] -> [(String, JsExp)] -> [(String, JsExp)] -> CompileWriter -- | Constructors. writerCons :: CompileWriter -> [JsStmt] -- | Fay to JS dispatchers. writerFayToJs :: CompileWriter -> [(String, JsExp)] -- | JS to Fay dispatchers. writerJsToFay :: CompileWriter -> [(String, JsExp)] -- | Configuration of the compiler. data CompileConfig CompileConfig :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> [(Maybe String, FilePath)] -> Bool -> Bool -> [FilePath] -> Bool -> Bool -> Maybe FilePath -> Bool -> Bool -> Bool -> Maybe FilePath -> [String] -> Maybe FilePath -> 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 -- | 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. 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] -- | Custom source location for fay-base configBasePath :: CompileConfig -> Maybe FilePath -- | State of the compiler. data CompileState CompileState :: Map ModuleName (Set QName) -> [(QName, [QName])] -> [(QName, [QName])] -> [(QName, Maybe QName, Type)] -> [(ModuleName, FilePath)] -> Integer -> Set Name -> ModuleScope -> Map ModuleName ModuleScope -> ModuleName -> Set ModulePath -> 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])] -- | Newtype constructor, destructor, wrapped type tuple stateNewtypes :: CompileState -> [(QName, Maybe QName, Type)] -- | 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 stateModuleScopes :: CompileState -> Map ModuleName ModuleScope -- | Name of the module currently being compiled. stateModuleName :: CompileState -> ModuleName stateJsModulePaths :: CompileState -> Set ModulePath -- | Adds a new export to _stateExports for the module specified by -- stateModuleName. addCurrentExport :: QName -> CompileState -> CompileState -- | Get all exports for the current module. getCurrentExports :: CompileState -> Set QName -- | Get exports from the current module originating from other modules. getNonLocalExports :: CompileState -> Set QName -- | Get all exports from the current module except newtypes. getCurrentExportsWithoutNewtypes :: 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 -- | The name of a module split into a list for code generation. data ModulePath -- | Construct the complete ModulePath from a ModuleName. mkModulePath :: ModuleName -> ModulePath -- | Construct intermediate module paths from a ModuleName. mkModulePaths -- A.B => [[A], [A,B]] mkModulePaths :: ModuleName -> [ModulePath] -- | Converting a QName to a ModulePath is only relevant for constructors -- since they can conflict with module names. mkModulePathFromQName :: QName -> ModulePath -- | Add a ModulePath to CompileState, meaning it has been printed. addModulePath :: ModulePath -> CompileState -> CompileState -- | Has this ModulePath been added/printed? addedModulePath :: ModulePath -> CompileState -> Bool instance Show CompileConfig instance Eq ModulePath instance Ord ModulePath instance Show ModulePath 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 -- | 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 internal FFI module. module 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 -- | 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 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 expression. compileExp :: Exp -> Compile JsExp -- | Compile a declaration. compileDecl :: Bool -> Decl -> Compile [JsStmt] -- | Compile the top-level Fay module. compileToplevelModule :: FilePath -> Module -> Compile [JsStmt] -- | Read a file and compile. compileModuleFromFile :: FilePath -> Compile [JsStmt] -- | Compile a source string. compileModuleFromContents :: String -> Compile [JsStmt] -- | Lookup a module from include directories and compile. compileModuleFromName :: ModuleName -> Compile [JsStmt] -- | Compile given the location and source string. compileModule :: FilePath -> String -> Compile [JsStmt] -- | Compile a parse HSE module. compileModuleFromAST :: 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