purescript-0.5.6.3: PureScript Programming Language Compiler

Safe HaskellNone
LanguageHaskell98

Language.PureScript.CodeGen.Common

Description

Common code generation utility functions

Synopsis

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.

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.