Lisplog

Blogging in Lisp

Search

Feed Aggregator

Rendered on Wed, 26 Jun 2019 23:32:25 GMT  newer latest older 
Next udpate: Thu, 27 Jun 2019 00:00:00 GMT feeds

Elm init seems to use old versions of modules

via Elm - Latest posts by @Michael_Mossey Michael Mossey on Wed, 26 Jun 2019 19:49:19 GMT

Thanks, I get it now!!

I think I’ve been able to find everything I need in elm, stuff that was moved out of core, like Random.

How to encode a value as JSON null

via Elm - Latest posts by @system system on Wed, 26 Jun 2019 17:01:46 GMT

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

ElmStatic with GitLab pages (and Netlify CMS)?

via Elm - Latest posts by @heyakyra on Wed, 26 Jun 2019 16:26:30 GMT

I’m new to Elm and Elmstatic but I’m excited to use them for a few projects. I’d like to be able to manage it with Netlify CMS and host it on GitLab pages.

Side note: The documentation for the former now lists Elmstatic after I created a merge request to do so! Hopefully that brings more attention to Elm and Elmstatic from Netlify CMS users :slightly_smiling_face:
* github netlify/netlify-cms/pull/2399

I filed a bug report for this, but I’m wondering if anyone has already gotten Elmstatic to build with the GitLab CI, and whether they could share a yml config file to do so!

Elm init seems to use old versions of modules

via Elm - Latest posts by @razze Kolja Lampe on Wed, 26 Jun 2019 11:22:01 GMT

Elm-lang is the old organization used for 0.18
everythig in elm is new, as that org is only in use in 0.19

Unfortunatly that name change caused a version reset

Pass elm/bytes through a port?

via Elm - Latest posts by @rupert Rupert Smith on Wed, 26 Jun 2019 10:50:43 GMT

Its a good point. If you really did want to put binary data in JSON format for sending over a Web API, you would most likely base64 encode it. This is already perfectly possibly with the existing APIs.

Perhaps what is needed is simply to allow Bytes to be passed over ports, but not to bother with encoders/decoders that turn them into Values representing javascript objects. The Bytes would have to be top-level arguments to the JS function and not embedded deeper as a field of some object.

Elm init seems to use old versions of modules

via Elm - Latest posts by @Michael_Mossey Michael Mossey on Wed, 26 Jun 2019 10:17:26 GMT

I installed elm 0.19 recently. In trying various things, I realized that ‘elm init’ creates a ‘elm.json’ pointing to what appear to be old versions of modules/libraries. For instance it points to

“elm/core” : “1.0.2”,
“elm/html” : “1.0.0”
and more.

It looks like the actual latest version of Core is “elm-lang/core” : “5.1.1”. Html should be “elm-lang/html”: 2.0.0

What’s going on here? What if I want to use later versions?

Mike

Pass elm/bytes through a port?

via Elm - Latest posts by @jreusch Joshua on Wed, 26 Jun 2019 10:11:06 GMT

The same argument could be made about elm/json. In fact, you cannot compile an Elm program without referencing elm/json as a (indirect) dependency, even though elm/core doesn’t depend on it.

The reason elm/json is such a fundamental package is because flags and ports can automatically generate code to decode/encode Javascript objects to Elm values and vice-versa. However, Javascript objects are infinitely more powerful than JSON. This thread for example asks for the ability to pass Bytes to Javascript, which have no native representation in JSON, but could be represented as a Javascript object (e.g. the native DataView or some TypedArray). Before elm/file existed, we (at work) passed raw Json.Encode.Values from the event handler through the port to process the Javascript File object there.

So, maybe we need to seperate communication with JSON things (like Web APIs) and communication with the host environment (basically the browser, so Javascript) more?

Pass elm/bytes through a port?

via Elm - Latest posts by @rupert Rupert Smith on Wed, 26 Jun 2019 09:09:51 GMT

Where would you put these functions if not in elm/json? If Bytes is now a fundamental data type in Elm, I don’t really see having it as a common dependency is much of an issue. Perhaps Bytes should even migrate into elm/core?

I think here you are talking about the case where on the JS side you have an Int32Array that you are passing into a port. When wrapped by DataView this gets presented as an 8-bit byte array. I also notice that elm/bytes understands what the host endianness is. So if you were to call Bytes.Decode.signedInt32 on these Bytes it should correctly decode to the right integer value.

Pass elm/bytes through a port?

via Elm - Latest posts by @rupert Rupert Smith on Tue, 25 Jun 2019 17:59:21 GMT

It has also been suggested that passing through as a list of ints might be more performant than base64. I will likely use one of these solutions despite being really horrible. Interested to understand if we can have a better way though.

Pass elm/bytes through a port?

via Elm - Latest posts by @joecorkerton on Tue, 25 Jun 2019 15:20:42 GMT

I ran into this issue recently, I was using a js package to parse a binary file format.

I worked around it by converting the bytes into a base64 string and passing that through the port, but I agree that it would have been nice to pass the bytes straight through the port

The right structure to build MPAs

via Elm - Latest posts by @tgelu Gelu Timoficiuc on Tue, 25 Jun 2019 13:29:52 GMT

Another small dummy app with multiple pages https://github.com/tgelu/elm-spa-example
I tried to both allow each page to have its own model/update/view/subscriptions but also that any page can use a “global” model which I called Session – inspiration from Richard’s elm-spa-example

Elm-Refine: Proposal

via Elm - Latest posts by @perty Per Lundholm on Tue, 25 Jun 2019 11:15:34 GMT

I made an attempt by creating a module that handles RangedInt which is an integer within a range.

type RangedInt
= RangedInt PayLoad

type alias PayLoad =
{ min : Int
, max : Int
, value : Int
}

When, for example, two RangedInt are added, a new RangedInt is created where the min and max are the sum of the ranges.

I used a Decoder to create RangedInt so only run-time checks.

decoder : Int -> Int -> Decoder.Decoder RangedInt
decoder min max =
    Decoder.int |> Decoder.andThen (helper min max)

helper : Int -> Int -> Int -> Decoder.Decoder RangedInt
helper min max value =
    if min > value || max < value then
        Decoder.fail <| outOfRangeErrorMessage min max value
    else
        Decoder.map (construct min max) Decoder.int

The right structure to build MPAs

via Elm - Latest posts by @perty Per Lundholm on Tue, 25 Jun 2019 10:57:02 GMT

If you want to see an example of using Browser.Navigation, you could look at my repo : https://github.com/perty/elm-navigation-test

It has also a Power Point presentation, should that make it easier to understand. A crude version is here on SlideShare: https://www.slideshare.net/PerLundholm/elm-spa-navigation

Pass elm/bytes through a port?

via Elm - Latest posts by @folkertdev Folkert De Vries on Tue, 25 Jun 2019 10:27:20 GMT

In general I think this should be added. Converting to anything else to pass it over a port negates any efficiency benefits of using bytes. There have been several cases where people ran into this limitation.

I’m not sure if adding to elm/json makes sense (creates a dependency to elm/bytes for elm/json).

A problem is that the elm-bytes package currently uses a DataView under the hood, which is a view on a byte array (i.e. elements are 8 bits wide). Therefore it is not obvious what should happen to a typed array with larger elements (e.g. Int32Array). Silently converting seems like a bad idea, but really any kind of conversion is bad because the whole goal of these data types is to be efficient. So either we don’t support typed arrays for the moment, or we need to be able to efficiently get them into the elm world.

We could also only support ArrayBuffer/DataView. A little against the elm spirit of finding a good general solution (that covers all low-level array types), but it would be practical.

Pass elm/bytes through a port?

via Elm - Latest posts by @rupert Rupert Smith on Tue, 25 Jun 2019 10:13:34 GMT

I take it there is no way to send Bytes through a port:

38| port sendBytes : Bytes.Bytes -> Cmd msg
         ^^^^^^^^^
I cannot handle that. The types that CAN flow in and out of Elm include:

    Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, tuples, records, and
    JSON values.

These functions could be added to elm-json:

-- In Json.Decode

bytes : Decoder Bytes

-- In Json.Encode

bytes : Bytes -> Value 

They would map onto the underlying DataView or ArrayBuffer on the JS side.

Can anyone see reasons why allowing this would be a bad idea? Would this be a worthwhile addition to the platform?

The right structure to build MPAs

via Elm - Latest posts by @Sebastian Sebastian on Tue, 25 Jun 2019 06:25:04 GMT

If you decide to use the SPA approach with Browser navigation here is another example https://github.com/sporto/elm-tutorial-app, smaller than the elm-spa-example

Aside from that, try to start by putting all the view, update, model code for a page inside one module. e.g. Just Page1.elm instead of State, Types etc. This will make your application simpler. Break this apart if you really need to.

Render Quake 3 Arena maps with Elm and WebGL!

via Elm - Latest posts by @cmditch Coury Ditch on Tue, 25 Jun 2019 05:35:23 GMT

Wow. This is really cool. Well done!

The Task Type Signature

via Elm - Latest posts by @luke Luke Westby on Mon, 24 Jun 2019 20:40:06 GMT

If the type is Task a, and errors are represented using Task (Result x a) then it’s no longer possible to conveniently chain Tasks with Task.andThen. Consider the following under the current API:

doFirstRequest
  |> Task.andThen (\value -> doSecondRequest value.id)
  |> Task.andThen (\value -> doThirdRequest value.name)

If the type we are dealing with is Task (Result Http.Error a) then the chain looks like this:

doFirstRequest
  |> Task.andThen
      (\result1 ->
        case result1 of
          Err err1 -> Task.succeed (Err err1)
          Ok value1 ->
            doSecondRequest value1.id
              |> Task.andThen
                  (\result2 ->
                    case result2 of
                      Ok value2 -> doThirdRequest value2.name
                      Err err2 -> Task.succeed (Err err2)
                  )

You can write a helper function to help with this unwrapping and rewrapping, but then you’re back to introducing more concepts because people will want to know how that function works and why you need it at all. With Promises in JS you can just do .then(), so why do I need this traverse function in Elm just to chain Tasks together? Etc. The issue with this is that Task.andThen and Task.map are the majority use case for working with Tasks, and it totally overtakes the complexity of sometimes having to deal with Never.

I suspect that in Rust this doesn’t become a problem because of syntax designed for dealing with Futures and unwrapping Results in a nice way.

Web-components interop (childNode issues)

via Elm - Latest posts by @luke Luke Westby on Mon, 24 Jun 2019 20:19:23 GMT

This is supposed to be achieved through shadow DOM. Shadow DOM isn’t perfect and there are certainly legitimate reasons not to use it right now, but it’s not clear to me why ion-header and ion-item would need to do so.

Unfortunately there’s no way Elm’s virtual DOM can detect and import DOM changes from outside the system without sacrificing its rendering speed, so I wouldn’t expect it to change to accommodate this use case. Something you might be able to try as a workaround is to declare your own custom element which renders your ion-header component within its own shadow DOM tree to hide its behavior from the Elm virtual DOM.

 newer latest older