Hacker Newsnew | past | comments | ask | show | jobs | submit | dmjio's commentslogin

https://github.com/dmjio/miso-lynx

Building native applications for iOS, Android and Huawei devices in Haskell.


This sounds very interesting. You say “native” but miso generates JavaScript, right? I’m not familiar with mobile development. Can you run JS natively on mobile devices?


Yes, miso uses the JS backend in GHC, and mobile phones have embedded JS interpreters (e.g. JavaScript Core). These interpreters can access native libraries to draw native views, or access native device APIs.

Projects like lynx and react-native automate this process using something akin to node-gyp, exposing kotlin / swift libraries via C ABI w/ a JS API. Miso accesses the kotlin / swift native modules by FFI'ing into the JS that exposes them.

The JS doesn't get compiled, but on Android it does get JIT'd. So it's "native" in the sense that the views drawn are native (not WebViews), and the device APIs are native, but not "native" in the sense that it's compiled.


That is very interesting. I never knew that JS could access native APIs. That's very promising for compilers that can generate JS, like GHC!



I'm working on miso-lynx

https://github.com/haskell-miso/miso-lynx

It's a way to build truly native iOS, Android and HarmonyOS applications in Haskell using https://lynxjs.org and https://github.com/dmjio/miso, it uses a similar approach to react-native.


This project is an integration between https://lynxJS.org and the Haskell miso web framework (https://github.com/dmjio/miso).


Miso has hydration w/ a global event event handler.

https://haskell-miso.org/


Haskell will accept you !

https://haskell-miso.org/


This post dismisses Elm on the basis of lack of typeclasses, but fails to mention miso (https://haskell-miso.org), that includes typeclasses. Miso is Elm-as-an-embedded-DSL written as a Haskell library for GHCJS that allows one to share types on the front and backend, take advantage of the entire Haskell ecosystem and has experienced commercial use.


I agree that Miso deserves a mention. It seems to be very actively maintained.

On the other hand, if you reject GHCJS then Miso is out of the running immediately. And the reason to reject GHCJS (big bundles, as mention in the article) is something you dont have in Elm/PureScript/ReasonML.

https://github.com/dmjio/miso


There is a company that has a 400 module miso application and the bundle size is not an issue (https://www.polimorphic.com). After closure compilation GZIP'ing, pre-rendering and caching of the JS, it's a one-time cost, and is negligible due to pre-rendering. We build websites for users, who care only about experience, not about how large the payload is. Payload only matters insomuch as it adversely affects user experience. This argument is strictly a developer concern and is in no way correlated with end-user feedback. There are many <1MB js payload size websites with 0 users.


After our bad experience in 2016 using GHCJS on a big project, we haven't considered it for anything since. Anything that arrived after that related to GHCJS just hasn't been on my radar ("a history of my own experience in this problem space").


Would you be able to share more details as to what caused this bad experience? My experience with GHCJS on a big project has been the opposite.


Note that Elm has typeclasses, they are just not exposed in the language: https://medium.com/@terezk_a/haskell-in-elm-terms-type-class...


A few companies have used this (https://haskell-miso.org/) to make useful software w/ Haskell.


Rewriting Elm in Haskell.

[0] Project Homepage: https://haskell-miso.org

[1] Github: https://github.com/haskell-miso/miso


If decoding json in Elm is considered hard, I'd recommend checking out miso (https://github.com/dmjio/miso), a Haskell re-implementation of the Elm arch. It has access to mature json libraries like aeson for that sort of thing, along with mature lens libraries for updating your model. Here's an example of decoding json with GHC.Generics using typeclasses. https://github.com/dmjio/miso/blob/master/examples/xhr/Main....


You don't need to switch a whole language because of JSON decoding. There are many tools that exist to aid you write JSON decoders in Elm. The language is not just about the architecture -- you can implement the architecture in any language, as Redux has proven. What people like about Elm is the compiler and design philosophy that radiates through the entire community. Switching to Haskell won't give you that, as the Haskell community has different priorities.

Here are some JSON tools for Elm:

- json-to-elm http://json2elm.com

- swagger-elm https://github.com/ahultgren/swagger-elm/

- elm-graphql https://github.com/jahewson/elm-graphql, https://github.com/jamesmacaulay/elm-graphql

- elm-export https://hackage.haskell.org/package/elm-export


Oh, this is awesome, json2elm really helps :) thanks, didn't know about it.


No problem! Glad you found it useful :) It's not perfect by any means, but it's not meant to be.


Yeah right, just to jumpstart the effort, especially when there are a lot of entities.


I am kinda waiting for Purescript to mature a tiny bit more in this regard, because it seems that they have something special brewing there, with their polymorphic record type and interesting take on type-level programming.

Because this [1], even though it seems to be just a experiment so far, looks really good.

I.e: doing

type MyTestStrMap = { a :: Int , b :: StrMap Int }

and then just calling

let result = handleJSON """ { "a": 1, "b": {"asdf": 1, "c": 2} } """

let newResult = doSomething (result:: Either MultipleErrors MyTestStrMap))

is kinda all I ever wanted in these haskell inspired languages?

[1] https://github.com/justinwoo/purescript-simple-json/blob/mas...


This is very cool. The example apps are relatively slow to load compared to the equivalent in some other frameworks (my favorite is Mithril for an idea of how small/fast these can get).

Was wondering whether it might be a slow server, but the app.js for the TodoMVC appears to be over a megabyte (1.21 MB, have a 4000 line Mithril app which is 500k uncompressed). What's up with that?


Can you give exact numbers and a testing method of how you tested and determined it is slow?


The router example on Github loads ~1.5 MB of JS files. Mithril's entire framework is 8kb gzipped (including a router).


ghcjs is a pretty heavyweight environment. It's actually translating the compiled core IR from GHC into JavaScript, and including a port of GHC's runtime system.

It can run basically any Haskell library. That includes the ability to run multithreaded Haskell code -- the JS RTS includes a scheduler. You also get Software Transactional Memory. Lazy evaluation works just as usual -- and so on.

The tradeoffs become worth it when you have a sufficiently valuable base of Haskell code that you want to run in the browser, and when your users aren't very constrained by page load time. Say, if you have some complicated tricky logic that you don't want to rewrite in another language, but you want to use it in your web app.


Aeson is SLOOW compared to 'JSON.parse' + GHCJS ffi. You lose a bit of correctness (JSON.parse can decode numbers only to the JS precision, ie. 53bits, while Aeson supports arbitrary precision through Scientific), and ability to decode streams in constant memory. But these are features which you most likely don't need in a web app.


>> Here's an example of decoding json with GHC.Generics using typeclasses.

>> https://github.com/dmjio/miso/blob/master/examples/xhr/Main....

There’s no reason to use genericParseJSON here, you can just write “instance FromJSON APIInfo”. Or leave the instance declaration as it is and safely rename your record fields to e.g. currentUserUrl instead of current_user_url.

The purpose of the camelTo function is to convert “camelCaseExample” into e.g. “camel_case_example” by passing ‘_’ as the first argument. But the APIInfo data structure already uses record fields with underscores in them.


There's also Fable-Elmish[1], which can be used with Fable[2], which is an F#-to-JS compiler.

[1] https://fable-elmish.github.io/elmish/

[2] http://fable.io/


To add to the other comments:

https://github.com/tiziano88/elm-protobuf


This looks really promising. Do you use it in production anywhere? Do you have any comparison of features with Elm?


Decoding json, the one most important format of the web, is hard in elm, a language supposedly designed for the web? I'm glad I didn't give it a try.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: