-- 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 @package fay @version 0.19.2 -- | Extra process functions. module Fay.System.Process.Extra -- | Read from a process returning both std err and out. readAllFromProcess :: FilePath -> [String] -> String -> IO (Either (String, String) (String, String)) -- | Extra directory functions. module Fay.System.Directory.Extra -- | Get all files in a folder and its subdirectories. Taken from Real -- World Haskell -- http:book.realworldhaskell.orgreadio-case-study-a-library-for-searching-the-filesystem.html getRecursiveContents :: FilePath -> IO [FilePath] -- | Extra list functions. module Fay.Data.List.Extra -- | Get the union of a list of lists. unionOf :: Eq a => [[a]] -> [a] -- | Flip of map. for :: Functor f => f a -> (a -> b) -> f b -- | 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 -- | Extra monadic functions. module Fay.Control.Monad.Extra -- | Word version of flip (>>=). bind :: Monad m => (a -> m b) -> m a -> m b -- | When the value is Just. whenJust :: Monad m => Maybe a -> (a -> m ()) -> m () -- | Wrap up a form in a Maybe. just :: Functor m => m a -> m (Maybe a) -- | Flip of mapMaybe. forMaybe :: [a] -> (a -> Maybe b) -> [b] -- | Monadic version of maybe. maybeM :: Monad m => a -> (a1 -> m a) -> Maybe a1 -> m a -- | Do any of the (monadic) predicates match? anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool module Fay.Exts.NoAnnotation type Alt = Alt () type BangType = BangType () type ClassDecl = ClassDecl () type Decl = Decl () type DeclHead = DeclHead () type Ex = Exp () type Exp = Exp () type ExportSpec = ExportSpec () type FieldDecl = FieldDecl () type FieldUpdate = FieldUpdate () type GadtDecl = GadtDecl () type GuardedAlts = GuardedAlts () type GuardedRhs = GuardedRhs () type ImportDecl = ImportDecl () type ImportSpec = ImportSpec () type Literal = Literal () type Match = Match () type Module = Module () type ModuleName = ModuleName () type ModulePragma = ModulePragma () type Name = Name () type Pat = Pat () type PatField = PatField () type QName = QName () type QOp = QOp () type QualConDecl = QualConDecl () type QualStmt = QualStmt () type Rhs = Rhs () type SpecialCon = SpecialCon () type SrcLoc = SrcLoc type SrcSpan = SrcSpan type SrcSpanInfo = SrcSpanInfo type Stmt = Stmt () type TyVarBind = TyVarBind () type Type = Type () unAnn :: Functor f => f a -> f () instance IsString (ModuleName ()) instance IsString (QName ()) instance IsString (Name ()) -- | Alias of MonadIO. module Fay.Control.Monad.IO -- | Alias of liftIO, I hate typing it. Hate reading it. io :: MonadIO m => IO a -> m a module Fay.Exts type X = SrcSpanInfo type Alt = Alt X type BangType = BangType X type ClassDecl = ClassDecl X type Decl = Decl X type DeclHead = DeclHead X type Ex = Exp X type Exp = Exp X type ExportSpec = ExportSpec X type FieldDecl = FieldDecl X type FieldUpdate = FieldUpdate X type GadtDecl = GadtDecl X type GuardedAlts = GuardedAlts X type GuardedRhs = GuardedRhs X type ImportDecl = ImportDecl X type ImportSpec = ImportSpec X type Literal = Literal X type Match = Match X type Module = Module X type ModuleName = ModuleName X type ModulePragma = ModulePragma X type Name = Name X type Pat = Pat X type PatField = PatField X type QName = QName X type QOp = QOp X type QualConDecl = QualConDecl X type QualStmt = QualStmt X type Rhs = Rhs X type SpecialCon = SpecialCon X type SrcLoc = SrcLoc type Stmt = Stmt X type TyVarBind = TyVarBind X type Type = Type X moduleName :: SrcInfo a => Module a -> ModuleName a moduleExports :: Module X -> Maybe (ExportSpecList X) moduleNameString :: ModuleName t -> String mkIdent :: String -> Name SrcSpanInfo noI :: SrcSpanInfo convertFieldDecl :: FieldDecl a -> ([Name a], BangType a) fieldDeclNames :: FieldDecl a -> [Name a] declHeadName :: DeclHead a -> Name a module Fay.Exts.Scoped type X = Scoped SrcSpanInfo type Alt = Alt X type BangType = BangType X type ClassDecl = ClassDecl X type Decl = Decl X type DeclHead = DeclHead X type Ex = Exp X type Exp = Exp X type ExportSpec = ExportSpec X type FieldDecl = FieldDecl X type FieldUpdate = FieldUpdate X type GadtDecl = GadtDecl X type GuardedAlts = GuardedAlts X type GuardedRhs = GuardedRhs X type ImportDecl = ImportDecl X type ImportSpec = ImportSpec X type Literal = Literal X type Match = Match X type Module = Module X type ModuleName = ModuleName X type ModulePragma = ModulePragma X type Name = Name X type Pat = Pat X type PatField = PatField X type QName = QName X type QOp = QOp X type QualConDecl = QualConDecl X type QualStmt = QualStmt X type Rhs = Rhs X type SpecialCon = SpecialCon X type SrcLoc = SrcLoc type Stmt = Stmt X type TyVarBind = TyVarBind X type Type = Type X noI :: Scoped SrcSpanInfo srcSpanInfo :: Scoped SrcSpanInfo -> SrcSpanInfo -- | All Fay types and instances. module 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 JsSetQName :: (Maybe SrcSpan) -> 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 Couldn'tFindImport :: ModuleName -> [FilePath] -> CompileError EmptyDoBlock :: CompileError FfiFormatBadChars :: SrcSpanInfo -> String -> CompileError FfiFormatIncompleteArg :: SrcSpanInfo -> CompileError FfiFormatInvalidJavaScript :: SrcSpanInfo -> String -> String -> CompileError FfiFormatNoSuchArg :: SrcSpanInfo -> Int -> CompileError FfiNeedsTypeSig :: Exp -> CompileError GHCError :: String -> CompileError InvalidDoBlock :: CompileError ParseError :: SrcLoc -> String -> CompileError ShouldBeDesugared :: String -> CompileError UnableResolveQualified :: QName -> CompileError UnsupportedDeclaration :: Decl -> CompileError UnsupportedEnum :: Exp -> CompileError UnsupportedExportSpec :: ExportSpec -> CompileError UnsupportedExpression :: Exp -> CompileError UnsupportedFieldPattern :: PatField -> CompileError UnsupportedImport :: ImportDecl -> CompileError UnsupportedLet :: CompileError UnsupportedLetBinding :: Decl -> CompileError UnsupportedLiteral :: Literal -> CompileError UnsupportedModuleSyntax :: String -> Module -> CompileError UnsupportedPattern :: Pat -> CompileError UnsupportedQualStmt :: QualStmt -> CompileError UnsupportedRecursiveDo :: CompileError UnsupportedRhs :: Rhs -> CompileError UnsupportedWhereInAlt :: Alt -> CompileError UnsupportedWhereInMatch :: Match -> CompileError -- | Compile monad. newtype Compile a Compile :: (RWST CompileReader CompileWriter CompileState (ErrorT CompileError (ModuleT (ModuleInfo Compile) IO))) a -> Compile a -- | Uns the compiler unCompile :: Compile a -> (RWST CompileReader CompileWriter CompileState (ErrorT CompileError (ModuleT (ModuleInfo Compile) IO))) a type CompileResult a = Either CompileError (a, CompileState, CompileWriter) type CompileModule a = ModuleT Symbols IO (CompileResult a) -- | 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 -> [(Maybe String, FilePath)] -> Bool -> Bool -> Bool -> [FilePath] -> Bool -> Bool -> Maybe FilePath -> Bool -> Bool -> Bool -> Maybe FilePath -> [String] -> Maybe FilePath -> [String] -> Bool -> Maybe FilePath -> CompileConfig -- | Run optimizations configOptimize :: CompileConfig -> Bool -- | Flatten function application? configFlattenApps :: 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 -- | Output a source map file as outfile.map. configSourceMap :: 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 -- | Produce strict and uncurried wrappers for all functions with type -- signatures in the given module configStrict :: CompileConfig -> [String] -- | Only invoke GHC for typechecking, don't produce any output configTypecheckOnly :: CompileConfig -> Bool configRuntimePath :: CompileConfig -> Maybe FilePath -- | State of the compiler. data CompileState CompileState :: Map ModuleName Symbols -> [(QName, [QName])] -> [(QName, [Name])] -> [(QName, Maybe QName, Type)] -> [(ModuleName, FilePath)] -> Integer -> ModuleName -> Set ModulePath -> Bool -> Map QName Type -> CompileState -- | Exported identifiers for all modules stateInterfaces :: CompileState -> Map ModuleName Symbols -- | Map types to constructors stateRecordTypes :: CompileState -> [(QName, [QName])] -- | Map constructors to fields stateRecords :: CompileState -> [(QName, [Name])] -- | 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, used for creating unshadowing -- variables. stateNameDepth :: CompileState -> Integer -- | Name of the module currently being compiled. stateModuleName :: CompileState -> ModuleName -- | Module paths that have code generated for them. stateJsModulePaths :: CompileState -> Set ModulePath -- | Use JS Strings instead of [Char] for string literals? stateUseFromString :: CompileState -> Bool -- | Module level declarations having explicit type signatures stateTypeSigs :: CompileState -> Map QName Type -- | 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. psMappings :: 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 -- | 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 a -> ModulePath -- | Construct intermediate module paths from a ModuleName. mkModulePaths -- A.B => [[A], [A,B]] mkModulePaths :: ModuleName a -> [ModulePath] -- | Converting a QName to a ModulePath is only relevant for constructors -- since they can conflict with module names. mkModulePathFromQName :: QName a -> ModulePath instance Show CompileConfig instance Eq ModulePath instance Ord ModulePath instance Show ModulePath instance Show CompileState instance Applicative Printer instance Monad Printer instance Functor Printer instance MonadState PrintState Printer instance Show CompileError instance Applicative Fay instance Functor Fay 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 JsLit instance Error CompileError instance Default PrintState instance MonadModule Compile 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 shouldExportStrictWrapper :: ModuleName a -> CompileConfig -> Bool 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 :: IsString s => s -> a -- | The Haskell→Javascript compiler. module Fay.Compiler -- | Runs compilation for a single module. runCompileModule :: CompileReader -> CompileState -> Compile a -> CompileModule a -- | Compile a Haskell source string to a JavaScript source string. compileViaStr :: FilePath -> CompileConfig -> PrintState -> (Module -> Compile [JsStmt]) -> String -> IO (Either CompileError (PrintState, CompileState, CompileWriter)) -- | Compile a module compileWith :: Monoid a => FilePath -> (a -> Module -> Compile a) -> (FilePath -> String -> Compile a) -> (X -> Module -> IO (Either CompileError Module)) -> String -> Compile (a, 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] -- | Compile a source string. compileModuleFromContents :: String -> Compile ([JsStmt], [JsStmt]) -- | Compile a parse HSE module. compileModuleFromAST :: ([JsStmt], [JsStmt]) -> Module -> Compile ([JsStmt], [JsStmt]) -- | Parse some Fay code. parseFay :: Parseable ast => FilePath -> String -> ParseResult ast -- | Main library entry point. module Fay -- | Compile the given file. compileFile :: CompileConfig -> FilePath -> IO (Either CompileError (String, [Mapping])) -- | Compile a file returning the state. compileFileWithState :: CompileConfig -> FilePath -> IO (Either CompileError (String, [Mapping], 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, [Mapping])) -- | 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. This will return the user supplied runtime -- if it exists. getConfigRuntime :: CompileConfig -> IO String -- | Get the default JS runtime source. getRuntime :: IO String