-- 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 -- -- -- -- See full history at: https://github.com/chrisdone/fay/commits @package fay @version 0.9.2.0 -- | Convert a Haskell value to a (JSON representation of a) Fay value. module Language.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, Read a) => Value -> Maybe a -- | All Fay types and instances. module Language.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 JsContinue :: JsStmt JsBlock :: [JsStmt] -> JsStmt -- | Expression type. data JsExp JsName :: JsName -> JsExp JsRawExp :: String -> JsExp JsFun :: [JsParam] -> [JsStmt] -> (Maybe JsExp) -> JsExp JsLit :: JsLit -> JsExp JsApp :: JsExp -> [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 JsInfix :: String -> JsExp -> JsExp -> JsExp JsObj :: [(String, 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 FfiFormatBadChars :: String -> CompileError FfiFormatNoSuchArg :: Int -> CompileError FfiFormatIncompleteArg :: CompileError FfiFormatInvalidJavaScript :: String -> String -> 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 -> Printer () -- | The JavaScript FFI interfacing monad. data Fay a -- | Configuration of the compiler. data CompileConfig CompileConfig :: Bool -> Bool -> Bool -> Bool -> [FilePath] -> Bool -> Bool -> [FilePath] -> Bool -> Bool -> Maybe FilePath -> Bool -> Bool -> CompileConfig configTCO :: CompileConfig -> Bool configInlineForce :: CompileConfig -> Bool configFlattenApps :: CompileConfig -> Bool configExportBuiltins :: CompileConfig -> Bool configDirectoryIncludes :: CompileConfig -> [FilePath] configPrettyPrint :: CompileConfig -> Bool configHtmlWrapper :: CompileConfig -> Bool configHtmlJSLibs :: CompileConfig -> [FilePath] configLibrary :: CompileConfig -> Bool configWarn :: CompileConfig -> Bool configFilePath :: CompileConfig -> Maybe FilePath configTypecheck :: CompileConfig -> Bool configWall :: CompileConfig -> Bool -- | State of the compiler. data CompileState CompileState :: CompileConfig -> [Name] -> Bool -> ModuleName -> [(Name, [Name])] -> [JsStmt] -> [JsStmt] -> [String] -> CompileState stateConfig :: CompileState -> CompileConfig stateExports :: CompileState -> [Name] stateExportAll :: CompileState -> Bool stateModuleName :: CompileState -> ModuleName stateRecords :: CompileState -> [(Name, [Name])] stateFayToJs :: CompileState -> [JsStmt] stateJsToFay :: CompileState -> [JsStmt] -- | Names of imported modules so far. stateImported :: CompileState -> [String] defaultCompileState :: CompileConfig -> CompileState -- | 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 FundamentalType FunctionType :: [FundamentalType] -> FundamentalType JsType :: FundamentalType -> FundamentalType ListType :: FundamentalType -> FundamentalType UserDefined :: Name -> [FundamentalType] -> FundamentalType DateType :: FundamentalType StringType :: FundamentalType DoubleType :: FundamentalType IntType :: FundamentalType BoolType :: FundamentalType -- | Unknown. UnknownType :: FundamentalType data PrintState PrintState :: Int -> Int -> [(SrcLoc, SrcLoc)] -> Int -> [String] -> PrintState psLine :: PrintState -> Int psColumn :: PrintState -> Int psMapping :: PrintState -> [(SrcLoc, SrcLoc)] psIndentLevel :: PrintState -> Int psOutput :: PrintState -> [String] newtype Printer a Printer :: State PrintState a -> Printer a runPrinter :: Printer a -> State PrintState a instance Monad Printer instance Functor Printer instance MonadState PrintState Printer instance Show CompileError instance Monad Fay instance Show JsLit instance Eq JsLit instance Show JsExp instance Eq JsExp instance Show JsStmt instance Eq JsStmt instance MonadState CompileState Compile instance MonadError CompileError Compile instance MonadIO Compile instance Monad Compile instance Functor Compile instance Applicative Compile instance Show FundamentalType instance Error CompileError instance Default PrintState instance Default CompileConfig module Language.Fay.FFI -- | In case you want to distinguish values with a JsPtr. data JsPtr a -- | Contains allowed foreign function types. class Foreign a -- | Declare a foreign action. ffi :: Foreign a => String -> a 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 Int instance Foreign Double instance Foreign () module Language.Fay.Prelude -- | The JavaScript FFI interfacing monad. data Fay a -- | 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 :: * -- | A fixed-precision integer type with at least the range [-2^29 .. -- 2^29-1]. The exact range for a given implementation can be -- determined by using minBound and maxBound from the -- Bounded class. data Int :: * 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 class Typeable allows a concrete representation of a type -- to be calculated. class Typeable a typeOf :: Typeable a => a -> TypeRep -- | The Data class comprehends a fundamental primitive -- gfoldl for folding over constructor applications, say terms. -- This primitive can be instantiated in several ways to map over the -- immediate subterms of a term; see the gmap combinators later -- in this class. Indeed, a generic programmer does not necessarily need -- to use the ingenious gfoldl primitive but rather the intuitive -- gmap combinators. The gfoldl primitive is completed by -- means to query top-level constructors, to turn constructor -- representations into proper terms, and to list all possible datatype -- constructors. This completion allows us to serve generic programming -- scenarios like read, show, equality, term generation. -- -- The combinators gmapT, gmapQ, gmapM, etc are all -- provided with default definitions in terms of gfoldl, leaving -- open the opportunity to provide datatype-specific definitions. (The -- inclusion of the gmap combinators as members of class -- Data allows the programmer or the compiler to derive -- specialised, and maybe more efficient code per datatype. Note: -- gfoldl is more higher-order than the gmap combinators. -- This is subject to ongoing benchmarking experiments. It might turn out -- that the gmap combinators will be moved out of the class -- Data.) -- -- Conceptually, the definition of the gmap combinators in terms -- of the primitive gfoldl requires the identification of the -- gfoldl function arguments. Technically, we also need to -- identify the type constructor c for the construction of the -- result type from the folded term type. -- -- In the definition of gmapQx combinators, we use -- phantom type constructors for the c in the type of -- gfoldl because the result type of a query does not involve the -- (polymorphic) type of the term argument. In the definition of -- gmapQl we simply use the plain constant type constructor -- because gfoldl is left-associative anyway and so it is readily -- suited to fold a left-associative binary operation over the immediate -- subterms. In the definition of gmapQr, extra effort is needed. We use -- a higher-order accumulation trick to mediate between left-associative -- constructor application vs. right-associative binary operation (e.g., -- (:)). When the query is meant to compute a value of type -- r, then the result type withing generic folding is r -- -> r. So the result of folding is a function to which we -- finally pass the right unit. -- -- With the -XDeriveDataTypeable option, GHC can generate -- instances of the Data class automatically. For example, given -- the declaration -- --
--   data T a b = C1 a b | C2 deriving (Typeable, Data)
--   
-- -- GHC will generate an instance that is equivalent to -- --
--   instance (Data a, Data b) => Data (T a b) where
--       gfoldl k z (C1 a b) = z C1 `k` a `k` b
--       gfoldl k z C2       = z C2
--   
--       gunfold k z c = case constrIndex c of
--                           1 -> k (k (z C1))
--                           2 -> z C2
--   
--       toConstr (C1 _ _) = con_C1
--       toConstr C2       = con_C2
--   
--       dataTypeOf _ = ty_T
--   
--   con_C1 = mkConstr ty_T "C1" [] Prefix
--   con_C2 = mkConstr ty_T "C2" [] Prefix
--   ty_T   = mkDataType "Module.T" [con_C1, con_C2]
--   
-- -- This is suitable for datatypes that are exported transparently. class Typeable a => Data a gfoldl :: Data a => (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> a -> c a gunfold :: Data a => (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a toConstr :: Data a => a -> Constr dataTypeOf :: Data a => a -> DataType dataCast1 :: (Data a, Typeable1 t) => (forall d. Data d => c (t d)) -> Maybe (c a) dataCast2 :: (Data a, Typeable2 t) => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a) gmapT :: Data a => (forall b. Data b => b -> b) -> a -> a gmapQl :: Data a => (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r gmapQr :: Data a => (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r gmapQ :: Data a => (forall d. Data d => d -> u) -> a -> [u] gmapQi :: Data a => Int -> (forall d. Data d => d -> u) -> a -> u gmapM :: (Data a, Monad m) => (forall d. Data d => d -> m d) -> a -> m a gmapMp :: (Data a, MonadPlus m) => (forall d. Data d => d -> m d) -> a -> m a gmapMo :: (Data a, MonadPlus m) => (forall d. Data d => d -> m d) -> a -> m a -- | The Monad class defines the basic operations over a -- monad, a concept from a branch of mathematics known as -- category theory. From the perspective of a Haskell programmer, -- however, it is best to think of a monad as an abstract datatype -- of actions. Haskell's do expressions provide a convenient -- syntax for writing monadic expressions. -- -- Minimal complete definition: >>= and return. -- -- Instances of Monad should satisfy the following laws: -- --
--   return a >>= k  ==  k a
--   m >>= return  ==  m
--   m >>= (\x -> k x >>= h)  ==  (m >>= k) >>= h
--   
-- -- Instances of both Monad and Functor should additionally -- satisfy the law: -- --
--   fmap f xs  ==  xs >>= return . f
--   
-- -- The instances of Monad for lists, Maybe and IO -- defined in the Prelude satisfy these laws. class Monad (m :: * -> *) -- | The Eq class defines equality (==) and inequality -- (/=). All the basic datatypes exported by the Prelude -- are instances of Eq, and Eq may be derived for any -- datatype whose constituents are also instances of Eq. -- -- Minimal complete definition: either == or /=. class Eq a (==) :: Eq a => a -> a -> Bool (/=) :: Eq a => a -> a -> Bool -- | 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 (+) :: 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 (++) :: [a] -> [a] -> [a] (.) :: (t1 -> t) -> (t2 -> t1) -> t2 -> t data Ordering GT :: Ordering LT :: Ordering EQ :: Ordering any :: (t -> Bool) -> [t] -> Bool compare :: Ord a => a -> a -> Ordering concat :: [[a]] -> [a] const :: a -> b -> a elem :: Eq a => a -> [a] -> Bool enumFrom :: Num a => a -> [a] enumFromTo :: (Eq t, Num t) => t -> t -> [t] fromIntegral :: Int -> Double filter :: (a -> Bool) -> [a] -> [a] find :: (a -> Bool) -> [a] -> Maybe a flip :: (t1 -> t2 -> t) -> t2 -> t1 -> t foldl :: (t1 -> t -> t1) -> t1 -> [t] -> t1 foldr :: (t -> t1 -> t1) -> t1 -> [t] -> t1 forM_ :: Monad m => [t] -> (t -> m a) -> m () fst :: (t, t1) -> t length :: [a] -> Int mod :: Double -> Double -> Double insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a] intercalate :: [a] -> [[a]] -> [a] intersperse :: a -> [a] -> [a] lookup :: Eq a1 => a1 -> [(a1, a)] -> Maybe a map :: (a -> b) -> [a] -> [b] mapM_ :: Monad m => (a -> m b) -> [a] -> m () maybe :: t -> (t1 -> t) -> Maybe t1 -> t not :: Bool -> Bool nub :: Eq a => [a] -> [a] null :: [t] -> Bool otherwise :: Bool prependToAll :: a -> [a] -> [a] reverse :: [a] -> [a] snd :: (t, t1) -> t1 sort :: Ord a => [a] -> [a] sortBy :: (t -> t -> Ordering) -> [t] -> [t] when :: Monad m => Bool -> m a -> m () zip :: [a] -> [b] -> [(a, b)] zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] max :: Double -> Double -> Double min :: Double -> Double -> Double -- | 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 :: CompileState -> 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 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) => CompileState -> (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 -- | Compile Haskell module. compileModule :: Module -> Compile [JsStmt] -- | Compile Haskell expression. compileExp :: Exp -> Compile JsExp -- | Compile the given input and print the output out prettily. printCompile :: (Show from, Show to, CompilesTo from to) => CompileConfig -> (from -> Compile to) -> String -> IO () -- | Compile a String of Fay and print it as beautified JavaScript. printTestCompile :: String -> IO () -- | Compile the top-level Fay module. compileToplevelModule :: Module -> Compile [JsStmt] -- | Format a JS string using js-beautify, or return the JS as-is if -- js-beautify is unavailable. prettyPrintString :: String -> IO String instance IsString Name instance CompilesTo Exp JsExp instance CompilesTo Module [JsStmt] module Language.Fay.Compiler -- | A result of something the compiler writes. class Writer a writeout :: Writer a => a -> String -> IO () -- | Something to feed into the compiler. class Reader a readin :: Reader a => a -> IO String -- | Compile file program to… compileFromTo :: CompileConfig -> FilePath -> FilePath -> IO () -- | Compile file program to… compileFromToReturningStatus :: CompileConfig -> FilePath -> FilePath -> IO (Either CompileError ()) -- | Compile readable/writable values. compileReadWrite :: (Reader r, Writer w) => CompileConfig -> r -> w -> IO () -- | Compile the given file. compileFile :: Reader r => CompileConfig -> r -> IO (Either CompileError String) -- | Compile the given module to a runnable program. compileProgram :: (Show from, Show to, CompilesTo from to) => CompileConfig -> String -> (from -> Compile to) -> String -> IO (Either CompileError String) -- | Print an this.x = x; export out. printExport :: Name -> String -- | Convert a Haskell filename to a JS filename. toJsName :: String -> String instance Reader FilePath instance Writer FilePath