5 ms·
There's also Fay <https://github.com/faylang/fay/wiki> https://github.com/faylang/fay/wiki> which provides a lighter-weight compilation of Haskell to JS, omitti
by joeyh 13y ago
There's also Fay <https://github.com/faylang/fay/wiki> https://github.com/faylang/fay/wiki> which provides a lighter-weight compilation of Haskell to JS, omitting stuff like threading and type classes.
Nice thing about Fay is you can read the generated javascript and see the 1:1 correspondance to the haskell code. This can be a nice way to get an intuition abvout how thunks are used to implement eg, infinite length lazy lists in haskell. There is also a live IDE <http://ide.fay-lang.org/> http://ide.fay-lang.org/>. I think this makes Fay an excellent teaching tool.
The way it seems to be shaping up is that ghcjs will be used for big serious projects where a javascript runtime that is measured in (IIRC) megabytes is acceptable and the full power of haskell is needed. While fay will be used as glue code for projects that are mostly written in server side Haskell and want to run some code in the browser, with access to the same types used on sever-side to eg, make AJAX nicer. Fay's entire runtime is 16 kb (unminified; with minification and other size optimisations a complete program can be as small as 3 kb) <https://github.com/faylang/fay/blob/master/js/runtime.js> https://github.com/faylang/fay/blob/master/js/runtime.js> which makes it work well in these niches.
- tome 13y agoI never really understood how Fay users could avoid using typeclasses, since it means (presumably) avoiding functors, applicatives, monads and all that other Haskelly stuff.
- tel 13y agoTypeclasses provide nothing but convenience there (see [1] for instance). The real power comes from the Algebraic Data Types which are intact. [1] http://www.haskellforall.com/2012/05/scrap-your-type-classes.html http://www.haskellforall.com/2012/05/scrap-your-type-classes...
- colanderman 13y agoI don't see how that mechanism provides subtyping (which typeclasses do)? Last I checked Haskell's structures weren't structurally typed.
- tel 13y agoYou could do it like in Agda, data ApplicativeI f = AI { pure :: forall a. a -> f a , ap :: forall a b. f (a -> b) -> f a -> f b , _FunctorI :: FunctorI f } data MonadI m = AI { bind :: forall a b. (a -> m b) -> m a -> m b , _ApplicativeI :: ApplicativeI m } return :: _MonadI m -> a -> m a return (MonadI { _ApplicativeI = ApplicativeI { pure = fn } }) = fn
- colanderman 13y agoAlmost, but that's not extensible: I can't declare some new typeclass Foo and then declare that every x s.t. Monad x is also Foo x without editing the definition of Monad.
- deleted 13y ago[deleted]
- tome 13y agoPersonally I wouldn't want to do the instance plumbing by hand.
- deleted 13y ago[deleted]
- swannodette 13y agoIt's been quite exciting to see all this activity around functional programming languages that target JavaScript. It's worth comparing both the GHCJS and Fay implementation approach with ClojureScript which has no runtime and ships with a full suite of efficient persistent data structures out of the box. It is also capable today of generating very fast code with little overhead over hand written JS http://swannodette.github.io/2013/06/10/porting-notchs-minecraft-demo-to-clojurescript/ http://swannodette.github.io/2013/06/10/porting-notchs-minec... (and is in fact why the persistent data structures we ship work so well). For the folks who swear by static typing, I expect core.typed will eventually provide that: http://github.com/clojure/core.typed http://github.com/clojure/core.typed
- Fishkins 13y agoI love clojure/clojurescript, but will core.typed really be comparable to Haskell's type system?
- swannodette 13y agoHaskell's type system is crafted for Haskell and core.typed is crafted for Clojure. I don't see how they can be compared given how different the two languages are.
- ithkuil 13y agowell, they still can be compared at some level. For example, haskell type checker is turing complete, i.e. you can do type level computation (see http://www.haskell.org/haskellwiki/Type_arithmetic http://www.haskell.org/haskellwiki/Type_arithmetic)
- colanderman 13y agoturing complete, i.e. you can do type level computation Turing completeness → computation, but the converse is not valid (i.e. computation → Turing completeness is not necessarily true). e.g. GADTs allow for some amount of type-level computation, but they do not in and of themselves form a Turing complete system. Alas, looking at your link, it does seem that Haskell's type system is sadly Turing-complete.
- luite 13y agoCode size is pretty big currently indeed. The highest priority is to make sure that we get all required patches to support GHCJS merged into GHC, before 7.8.1 is out. GHCJS is a standalone, cabal installable compiler (it uses the GHC API), but some features, like the "foreign import javascript" FFI need some minor changes in GHC itself. We haven't really spent much time optimizing for code size yet, and there's still lots of low hanging fruit. We will never reach 3kB minified though, for example the JSBN library (that we use to implement Integer) alone is a lot bigger than that. The GHCJS linker does tree shaking: Only functions that are reachable from main are included in the result. We have some plans to extend this a bit, an old version already had incremental loading, but that has not yet been implemented for the new code generator.
- chongli 13y ago>The GHCJS linker does tree shaking Ahh, so does this mean we can shake out entire libraries like JSBN if we avoid using Integer?
- luite 13y agoIf you're really careful and not use anything from base that might use an Integer ;) Currently non-Haskell dependencies are managed per package, so if anything from integer-gmp is linked, it will include the whole JSBN. If you want to weed out the unused JSBN part, you can use closure compiler (although the new code generator will probably still have a few incompatibilities with it).
- chongli 13y agoOh, so does that mean I can't do anything that uses the Integral class, for example? Even if I make sure all my types are Ints?
- luite 13y agoYou can use the Integral class (when compiling, the instance gets converted to an extra dictionary argument, if you never use the instance the dictionary will be unreachable) But Integer is really hard to avoid in general, for example the Show instance for Double depends on it.
- cantankerous 13y agoI like Fay, but I thought the no-typeclasses thing was attributed to the fact that they used GHC as a front end and unwinding them out of GHC Core was to tall of an order for the time being? The Github page/discussion seemed to say as much IIRC. I'd really like to have typeclasses in Fay. Like REALLY like to have typeclasses in Fay. Also threading in Haskell isn't a first-class thing. I'm not sure what you mean by that. How does one omit threading if it's not really part of the language spec to begin with? Care to expand?
- kryptiskt 13y ago> How does one omit threading if it's not really part of the language spec to begin with? Care to expand? Not the OP but I can't resist answering. Threading isn't really part of the language proper, but as a lazy language can make flow control from language or library indistinguishable that isn't a very important distinction. What matters is that GHC has an excellent threading implementation in its runtime and that the compiler has the primitives to build the Haskell concurrency libraries on.