Skip to content

Instantly share code, notes, and snippets.

@JoeyEremondi
Last active August 29, 2015 14:15
Show Gist options
  • Save JoeyEremondi/e077c18c5d7bdb70ce14 to your computer and use it in GitHub Desktop.
Save JoeyEremondi/e077c18c5d7bdb70ce14 to your computer and use it in GitHub Desktop.
Elm-public-API-options
import qualified AST.Module as Module
----------------------------------------------------------
-- These are the optimizing functions I'm writing that will be public
-- JS could be added to the output Map as well, if we wanted
{-| Given interfaces from compiled Elm modules and their compiled JavaScript,
attempt to optimize the given modules, assuming that the program will be run from
the entry point of `main` within the given main module-}
optimizeProgram
:: PublicModule.Name
-> Map.Map PublicModule.Name (PublicModule.Module, PublicModule.Interface)
-> Map.Map PublicModule.Name (PublicModule.Module, PublicModule.Interface)
{-| Given interfaces from compiled Elm modules and their compiled JavaScript,
attempt to optimize the given modules, assuming that all functions in the given set of modules
must be avaliable as a library, possibly to be called from JavaScrip.
The main purpose of this is to prevent library functions from being marked as "dead code"-}
optimizeLibrary
:: [PublicModule.Name]
-> Map.Map PublicModule.Name (PublicModule.Module, PublicModule.Interface)
-> Map.Map PublicModule.Name (PublicModule.Module, PublicModule.Interface)
------------------ Option 1 ----------------------------------
data Interface = Interface {
iModule :: Module.CanonicalModule
--The rest is as it currently is
}
--API stays the same as before
{-| Compiles Elm source code to JavaScript. -}
compile
:: String
-> String
-> String
-> Map.Map PublicModule.Name PublicModule.Interface
-> Either String (PublicModule.Interface, String)
-------------------------Option 2-------------------------------------
--We have a parse function, which generates the necessary info for optimizing for one module
--Basically like Compile, but it doesn't generate JS
parse
:: String
-> String
-> String
-> Map.Map PublicModule.Name PublicModule.Interface
-> Either String (PublicModule.Module, PublicModule.Interface)
--Then we'd have a function that took the result of a bunch of parses, possibly optimized, and generate all the JS
generateAndLink
:: Map.Map PublicModule.Name (PublicModule.Module, PublicModule.Interface)
-> Either String String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment