-- 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 -- --
-- 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, -- --
-- 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