Lisplog

Blogging in Lisp

Search

Feed Aggregator Page 660

Rendered on Tue, 13 Oct 2020 19:03:55 GMT  newer latest older 

Composing a Task with a function that returns a Cmd

via Elm - Latest posts by @MartinS on Tue, 13 Oct 2020 18:09:08 GMT

Someone can correct me if I’m wrong about this but I believe storing Cmd or Task in your Msg/Model has the same drawbacks as storing functions.

Composing a Task with a function that returns a Cmd

via Elm - Latest posts by @ursi Mason Mackaman on Tue, 13 Oct 2020 17:17:50 GMT

A similar but slightly different approach

init : () -> ( Model, Cmd Msg )
init _ =
    ( ()
    , Time.now
        |> Task.map timeToCmd
        |> Task.perform RunCmd
    )


type Msg
    = RunCmd (Cmd Msg)
    | ...


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        RunCmd cmd ->
            ( model, cmd )
        ...

Reasons that people were forced to move from Elm to something else?

via Elm - Latest posts by @solificati on Tue, 13 Oct 2020 15:40:58 GMT

I’m working in team that does back office apps for my company. We tried Elm and wrote few apps but now we advice against using it.

It boils down to the fact that Elm is a middle ground between typescript and advanced functional language and we don’t get much benefit from this.

On the one hand it is really difficult to create composable and reusable library of widgets. Anything interactive leads to a lot of boilerplate and weird patterns. And to be honest, Typescript type system is enough for widget library. We still don’t get runtime errors. Reported errors are mostly about rendering and here Elm also does not help.

On the other hand, Elm type system is limited and we can’t express our domain through it. Our apps deal with complex information and we’d like to have more tools at our disposal than records and tagged sums. We’d like to enforce laws and relations between data, even if we need to pay with steeper learning curve.

Few months ago, when we decided that pure Elm is not a viable solution (due to it’s focus on purity and lack of FFI, which we understand) we decided to test three approaches:

  1. Elm + WebComponents
  2. Reason for logic and React-Typescript components through genType
  3. Reason with ReasonReact for components

We ruled out first variant, because it brings us very little. If we start using a lot of web components we’re losing Elm guarantees. WebComponents are transparent for Elm and “string typed”.

But we also have team focused on marketing pages and they are very pleased with Elm + WebComponents approach. Domain logic is not very complicated there and shelf time is shorter.

Reasons that people were forced to move from Elm to something else?

via Elm - Latest posts by @lucamug on Tue, 13 Oct 2020 12:35:43 GMT

I experienced a couple Elm projects that eventually were rewritten in other languages.

Even though it is a minority, as we have several projects now in Elm, I was puzzled about why this happened.

I guess there were multiple factors but the common denominator was about individuals that battled on a daily basis against Elm instead of feeling empowered. They learned the syntax but struggled with concepts like purity and immutability.

Complains were trivial. I remember things like “Why have to be so difficult to get the time?” or “Why are we using Elm while it is still in version 0.x?”. Or something like “I want to become very good at React”.

In my experience these individuals also tended to have strong personalities used to convince people around them. Also for some coincidence, all of them left the company shortly after. This is an anecdotal, but interesting coincidence to me.

Some other time Elm clicked perfectly. For example we had an Intern that was able to learn Elm and write better code than most of us. He ended up crafting a nice piece of code that, unfortunately, is among the projects that was eventually converted to typescript after he left.

What makes some people to love Elm and others to struggle?

Package install timeout 0.19.1

via Elm - Latest posts by @aurelien_campeas Aurélien Campéas on Tue, 13 Oct 2020 11:56:02 GMT

Are you behind a proxy ? If so is your proxy configuration exposed to elm ?

Trouble with text inputs and double update roundtrips

via Elm - Latest posts by @jreusch Joshua on Tue, 13 Oct 2020 10:11:11 GMT

It is actually enough to just use something like Html.Events.on "input" Html.Events.targetValue instead of Html.Events.onInput.

As explained in the notes here, onInput creates a synchronous event handler and makes sure all commands are run immediately after update, to make sure the browser treats them as “happening after user interaction”. This bites you here:

  1. User types something, TextUpdated is fired synchronously.
  2. update recieves your message, returns the old contents of the <textarea>.
  3. view is also run synchronously, to prevent the model and the view from diverging
  4. Your command is executed, goes through update, and causes the view to change again to the desired state. Since the VDOM caused the textarea to update twice, history and selection is lost.

So it may be a bug in the runtime, since it calls view before running synchronous commands. I’m not sure what the intended behaviour in that case is.

Here is an ellie logging what is happening here: https://ellie-app.com/bf3fGX2pLCJa1

grafik

it also shows a way of getting the timestamp synchronously by (ab)using Json.Decode, maybe don’t do this.

Do you put tests outside the `tests/` folder?

via Elm - Latest posts by @lydell Simon Lydell on Tue, 13 Oct 2020 06:46:32 GMT

@Sebastian Awesome, thanks! Really nice to see that it finds all your tests and is fast. But … I now realize I forgot to say something. When I tested my branch on the test suite at work (which uses tests/) I also got several seconds better times, but then realized I wasn’t using the latest elm-test to begin with. So I updated to elm-test@0.19.1-revision4 and then speed difference shrunk to 0.5 seconds (still a win though!).

If you also have the energy to compare times for elm-test src/ (no globs, let elm-test figure out where the tests are) that would be awesome! I suspect very few people actually that, but my PR should be as fast as elm-test@0.19.1-revision4 or a tiny bit slower (this depends on how much elm-test decides to parallelize…).

Trouble with text inputs and double update roundtrips

via Elm - Latest posts by @ursi Mason Mackaman on Tue, 13 Oct 2020 06:12:58 GMT

How about this?
https://ellie-app.com/bdXzGmL5S6Va1

  • only uses one call to update
  • gets the exact time of the user’s input
  • no problems with the cursor

Instead of using onInput, you useon "input" and provide you own decoder for the event. Events have a timeStamp property that tells you when the event occurred relative to the time origin (in ms). You can pass the time origin into elm via a flag (using performance.timeOrigin) and then use that to get the absolute timestamp for your event in the update function.

Alexander Artemenko: tesseract-capi

via Planet Lisp by on Mon, 12 Oct 2020 20:24:53 GMT

It has nothing in common with the magic artefact, but anyway is able to do pretty cool things!

This library is a wrapper around Tesseract OCR and is suitable for an image to text transformations.

To test this system, you need to install the Tesseract library first. On OSX just do:

brew install tesseract

The CL library is not in the Quicklisp but can be installed from the https://ultralisp.org Follow the instruction from the repository:

https://github.com/egao1980/tesseract-capi

To make it work, you'll need a trained data for Tesseract engine. Happily, the Homebrew package includes some files for the English language.

To find out a path, do:

[poftheday] echo $(brew --prefix tesseract)/share/tessdata/
/usr/local/opt/tesseract/share/tessdata/

Now we can test this library on this sample from the repository:

Here is how to translate this image into the text:

POFTHEDAY> (tesseract-capi::tessversion)
"4.1.1"

POFTHEDAY> (let ((tesseract-capi:*tessdata-directory*
                   "/usr/local/opt/tesseract/share/tessdata/"))
             (tesseract-capi:image-to-text
              (asdf:system-relative-pathname
               :tesseract-capi "tests/data/fox.png")))
"This is a lot of 12 point text to test the
ocr code and see if it works on all types
of fle format

The quick brown dog jumped over the
lazy fox. The quick brown dog jumped
over the lazy fox. The quick brown dog
jumped over the lazy fox. The quick
brown dog jumped over the lazy fox
"

Now let's try it on this XKCD comic:

POFTHEDAY> (let ((tesseract-capi:*tessdata-directory*
                   "/usr/local/opt/tesseract/share/tessdata/"))
             (tesseract-capi:image-to-text
              "docs/media/0203/xkcd-312.png"))
"A GODS LAMENT
SOME SAID THE WORLD SHOULD BE IN PERL;
SOME. SAID IN LISP
NOW, HAVING GIVEN BOTH A WHIRL,
I HELD WITH THOSE WHO FAVORED PERL.
BUT I FEAR WE PASSED TO MEN
A DISAPPOINTING FOUNDING MYTH,
AND SHOULD WE WRITE IT ALL AGAIN,
TO ENO IT WITH
A CLOSE -PAREN.
SY i
\\ ad an ran
cS co V
a, em oo
2 ee eee
@ P= : } 0.\" :
a OO
"

As you can see, it outputs some junk at the end, but main text is recognized almost perfectly!

I think, this is a pretty cool library! For example, you can use it plus Montezuma to build a personal search engine for your image and scans collection. It's a matter of one night.

Do you put tests outside the `tests/` folder?

via Elm - Latest posts by @Sebastian Sebastian on Mon, 12 Oct 2020 22:39:35 GMT

I tried

elm-test

Duration: 665 ms
Passed: 880
Failed: 0

real 0m5.436s
user 0m12.894s
sys 0m7.801s

lydell/node-test-runner#js

Duration: 636 ms
Passed: 880
Failed: 0

real 0m1.496s
user 0m4.137s
sys 0m0.758s

Your fork was consistently faster. 6 secs vs 2 secs.

Reasons that people were forced to move from Elm to something else?

via Elm - Latest posts by @gampleman Jakub Hampl on Mon, 12 Oct 2020 11:00:03 GMT

At my previous job, we got together a cross-functional team to design, build and deliver a project. The team was me as the front end engineer, a full stack engineer, a data-scientist/project lead, and a part time GIS expert. I was a reasonably seasoned Elm developer and the fullstack engineer was quite keen to learn, the other two had no opinion so we built the front end in Elm. This was both super fun and quite productive.

The project wasn’t huge, but there were 2 interesting technical challenges:

  1. Mapping and heavy duty geospatial visualization. gampleman/elm-mapbox was born of this. On the backend we used Postgress with PostGIS (these are really amazing BTW)
  2. i18n. We used a i18n service to do the translations, then used a build time script to generate Elm modules, so we had a different script for each locale. As the project needed only 2 locales, this was pretty manageable. The backend then dynamically served the correct bundle to each client.

After the first phase of the project, the project was put on hold for a bit, and all the other team members eventually left the company. The project went on with a v2, survived a ton of churn, scope changes, politics (literally in this case) and delays. Nonetheless, we shipped a successful version.

At this point, we had hired some new people. At this point the company had 2 senior front-end engineers, 1 graduate developer, 0 full stack and 1 senior backend engineers. We focused for about 6 months on a different React based project. Nonetheless, the other front-end engineer refused to learn Elm. He simply didn’t believe that it had any career potential for him and wanted to focus on other stuff. While the graduate developer might have been interested, he was simply too busy trying to get his head around all the stuff in the React ecosystem.

So when I handed in my notice (with a 1 month notice period), my manager told me that I will spend my notice period rewriting this project into React. As you may imagine, this was not really what I was hoping to spend my time doing.

On the plus side, Elm -> React+Redux is a pretty straightforward porting job, as many of the concepts are very similar. The main thing I was missing was probably Elm-UI, as there doesn’t seem to be a great alternative.

On the negative side, the asset size ballooned. Performance was not great either. The code, despite being a clean rewrite wasn’t any better, rather some of the nice guarantees of the Elm code were completely lost in translation.

For me this was a pretty disappointing experience and I wonder if we need something like “How to use Elm at Work”: “How to make sure they stick to Elm after I leave?”.

Do you put tests outside the `tests/` folder?

via Elm - Latest posts by @lydell Simon Lydell on Mon, 12 Oct 2020 06:13:19 GMT

@sebastian Thanks for the reply! Feel free to answer the editor questions as well. :pray:

@sebastian @grigorious Would you mind trying my branch in your project? npm install --save-dev lydell/node-test-runner#js to install, then run the tests like you usually do (assuming you have a local install). I’m interested in (1) if the same amount of tests is run and (2) how long it takes*. I’m expecting a half a second speedup.

* Note that the duration that elm-test reports doesn’t include compilation time, which is what I’ve worked on. Run time npx elm-test 'src/**/*Test.elm' a couple of times before and after you’ve installed my branch to see the full duration.

Reasons that people were forced to move from Elm to something else?

via Elm - Latest posts by @G4BB3R Gabriel Torrecillas Sartori on Mon, 12 Oct 2020 03:31:43 GMT

Once I developed a dashboard in elm-spa / elm-ui. It was very fast, in 3 days I done it. The technology choice was free, but then the manager said that the sales department sold it as a react app and he forgot to tell me, and I needed to redo, it took me 7 days plus 1 extra day some time later to fix some bugs. There is also the time to create new features and to maintain that another employee will have in the future, with Elm it could be much easier. That’s my experience with it.

Svg-folder-to-elm-module: import SVG icons into your elm codebase

via Elm - Latest posts by @system system on Mon, 12 Oct 2020 00:14:20 GMT

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

Do you put tests outside the `tests/` folder?

via Elm - Latest posts by @Sebastian Sebastian on Sun, 11 Oct 2020 23:18:10 GMT

We put the tests next to the tested modules in src and use elm-test 'src/**/*Test.elm'

Do you put tests outside the `tests/` folder?

via Elm - Latest posts by @lydell Simon Lydell on Sun, 11 Oct 2020 19:52:33 GMT

Thanks! Final question area:

  1. Which editor do you use, and do you use any Elm plugin?

  2. If you use an Elm plugin, does it understand import Test and import Expect in your *Spec.elm files, or does it mark them as errors?

  3. If it doesn’t mark them as errors, is it because you have elm-explorations/test in regular "dependencies" rather than in "test-dependencies" in elm.json?

Do you put tests outside the `tests/` folder?

via Elm - Latest posts by @grigorious on Sun, 11 Oct 2020 19:14:00 GMT

Thank you for the first point, I did not know that glob was already used. As to the second point that was an error from my part - was looking at my angular code and added *.spec.elm automatically - in reality I’m using ChiSquaredSpec.elm

The angular style documentation rationalises the use of .spec suffix with:

  • Provides a consistent way to quickly identify tests.
  • Provides pattern matching for test runners

I also like to think of this tests as a sort of documentation - concretely for my modules this documents how some functions behave in edge cases -> hence spec instead of test. (The ChiSquared module uses a distribution table - so it is useful to define what happens when a value is not found in the table and so on …)

Do you put tests outside the `tests/` folder?

via Elm - Latest posts by @lydell Simon Lydell on Sun, 11 Oct 2020 16:07:42 GMT

Thanks! Two things:

  1. If you wrap the glob in quotes, elm-test will resolve the glob for you (also using glob): elm-test "src/**/ChiSquared.spec.elm"

  2. I tried to create .spec.elm files, but I get this error:

~/stuff/test-spec
❯ npx elm-test src/ChiSquared.spec.elm
-- UNEXPECTED FILE NAME --------------------------------------------------------

I am having trouble with this file name:

    /Users/lydell/stuff/test-spec/src/ChiSquared.spec.elm

I found it in your /Users/lydell/stuff/test-spec/src/ directory which is good,
but I expect all of the files in there to use the following module naming
convention:

    +--------------+----------------------------------------------------+
    | Module Name  | File Path                                          |
    +--------------+----------------------------------------------------+
    | Main         | /Users/lydell/stuff/test-spec/src/Main.elm         |
    | HomePage     | /Users/lydell/stuff/test-spec/src/HomePage.elm     |
    | Http.Helpers | /Users/lydell/stuff/test-spec/src/Http/Helpers.elm |
    +--------------+----------------------------------------------------+

Notice that the names always start with capital letters! Can you make your file
use this naming convention?

Note: Having a strict naming convention like this makes it a lot easier to find
things in large projects. If you see a module imported, you know where to look
for the corresponding file every time!

Compilation failed while attempting to build /Users/lydell/stuff/test-spec/src/ChiSquared.spec.elm

You must be doing something more to get your setup to work?

Webpack 5 updated example

via Elm - Latest posts by @ronanyeah on Sun, 11 Oct 2020 15:18:58 GMT

I updated my Elm + Webpack example repo for the new Webpack 5 release. Pretty similar to v4 but webpack-dev-server command has changed to webpack serve.

Reasons that people were forced to move from Elm to something else?

via Elm - Latest posts by @jhbrown Jeremy H. Brown on Sun, 11 Oct 2020 15:01:37 GMT

(Oh yeah, and to provide a cathartic outlet for the victims.)

 newer latest older