faylang / fay

A proper subset of Haskell that compiles to JavaScript
https://github.com/faylang/fay/wiki
BSD 3-Clause "New" or "Revised" License
1.29k stars 86 forks source link

Multiple input files and -o clobbers the output #347

Closed kfish closed 9 years ago

kfish commented 10 years ago

I would like to structure my Haskell code in separate files (one file per module, as Haskell requires), but generate one output javascript file.

Currently, if I use a commandline like:

fay --package fay-text -o output.js Foo.hs Bar.hs

then fay will:

  1. compile Foo.hs, writing the result to output.js
  2. compile Bar.hs, overwriting output.js

So -o cannot be used with multiple files.

If I instead use multiple invocations:

fay --package fay-text Foo.hs
fay --package fay-text Bar.hs

then the resulting Foo.js and Bar.js will contain redundant copies of the same code (RTS, stdlib and fay-text library code). If I build with --no-stdlib --library, then I still get redundant copies of fay-text.

bergmark commented 10 years ago

One simple (and perhaps better?) solution for this is to have a top level module that imports both Foo and Bar.

kfish commented 10 years ago

Ah! I can make a toplevel module Main.hs that does nothing but import:

module Main where

import Foo
import Bar

and build it with:

fay --package fay-text Main.hs

it does the right thing, without any interference between Foo and Bar. When generating modules to call from javascript, I can do:

fay --package fay-text Main.hs --strict Foo,Bar

which will create Main.js, defining Strict.Foo and Strict.Bar. That worksforme.

(We could probably fiddle it so that giving multiple arguments is equivalent to compiling such an import-only module)

bergmark commented 10 years ago

Also related to #330 by the way.

Some possible solutions:

I'll reopen this, the current behavior is unintuitive/broken.

bergmark commented 9 years ago

Spring cleaning. Lack of activity, it's unlikely that this will happen. Use a top level module.