Safe Haskell | None |
---|---|
Language | Haskell98 |
Common code generation utility functions
- identToJs :: Ident -> String
- identNeedsEscaping :: String -> Bool
- identCharToString :: Char -> String
- nameIsJsReserved :: String -> Bool
- moduleNameToJs :: ModuleName -> String
- lookupConstructor :: Environment -> Qualified ProperName -> (DataDeclType, ProperName, Type)
- isOnlyConstructor :: Environment -> Qualified ProperName -> Bool
- isNewtypeConstructor :: Environment -> Qualified ProperName -> Bool
- getConstructorArity :: Environment -> Qualified ProperName -> Int
- isNullaryConstructor :: Environment -> Qualified ProperName -> Bool
Documentation
identToJs :: Ident -> String Source
Convert an Ident into a valid Javascript identifier:
- Alphanumeric characters are kept unmodified.
- Reserved javascript identifiers are prefixed with
$$
. - Symbols are prefixed with
$
followed by a symbol name or their ordinal value.
identNeedsEscaping :: String -> Bool Source
Test if a string is a valid JS identifier without escaping.
identCharToString :: Char -> String Source
Attempts to find a human-readable name for a symbol, if none has been specified returns the ordinal value.
nameIsJsReserved :: String -> Bool Source
Checks whether an identifier name is reserved in Javascript.
moduleNameToJs :: ModuleName -> String Source
lookupConstructor :: Environment -> Qualified ProperName -> (DataDeclType, ProperName, Type) Source
Finds the value stored for a data constructor in the current environment. This is a partial function, but if an invalid type has reached this far then something has gone wrong in typechecking.
isOnlyConstructor :: Environment -> Qualified ProperName -> Bool Source
Checks whether a data constructor is the only constructor for that type, used to simplify the check when generating code for binders.
isNewtypeConstructor :: Environment -> Qualified ProperName -> Bool Source
Checks whether a data constructor is for a newtype.
getConstructorArity :: Environment -> Qualified ProperName -> Int Source
Checks the number of arguments a data constructor accepts.
isNullaryConstructor :: Environment -> Qualified ProperName -> Bool Source
Checks whether a data constructor has no arguments, for example, Nothing
.