Questions tagged [elm]

Elm is a functional programming language for writing web applications that can fully replace, or interoperate with, HTML/CSS/JavaScript.

Elm is a functional programming language that is interoperable with HTML/CSS/JavaScript. It is optimized for creating web UIs, supporting complex user input without using callbacks.

Key features

  • Static types with type inference, with the best compiler errors ever
  • No runtime exceptions
  • No null or undefined in the language
  • Enforces semver for all Elm packages (you must update version number if you make a breaking change)

Resources:

Elm Books

1885 questions
9
votes
2 answers

Why can't I use `onWithOptions` in elm 0.19

I am attempting to upgrade an elm application from 0.18 to 0.19. I am stuck with this error - Detected errors in 1 module. -- BAD IMPORT ---------------------------------------- src/Views/Interaction.elm The…
brendangibson
  • 2,377
  • 2
  • 21
  • 36
9
votes
0 answers

Elm 0.19: elm make "not enough bytes" error when compiling

I am suddenly receiving this error message when compiling my app: elm make src/App.elm --output ../assets/javascripts/elm/App.js elm: not enough bytes CallStack (from HasCallStack): error, called at libraries/binary/src/Data/Binary.hs:212:21 in…
wmakley
  • 1,233
  • 9
  • 18
9
votes
3 answers

How to listen for both keypress and keydown events in Elm?

I want to listen to both keypress and keydown events in Elm. But if I have the following, only the keydown events will be listened to: textarea [ onWithOptions "keypress" (Options False True) <| Json.Decode.map KeyPress keyCode ,…
at.
  • 50,922
  • 104
  • 292
  • 461
9
votes
1 answer

Specifying Http headers in Elm

My Elm program works fine with the code (excerpt) below using http.get, but I had to changed it to a custom request to specify JWT in the header, and I get the following error due to type mismatch. I think I need to change the type of request to…
Jason O.
  • 3,168
  • 6
  • 33
  • 72
9
votes
3 answers

Is there a less verbose way to unwrap maybe values in Elm

I've been running into a frequent issue in elm where I have a function that depends on multiple maybe values being Just. Is there a less verbose way to write this code: commandIf apples bananas oranges = case apples of Just…
tanman
  • 1,379
  • 1
  • 10
  • 19
9
votes
3 answers

Elm: How to pretty print the model in the browser?

This question is kind of silly but i didn't find a straight forward solution. Assuming I have a model that resembles this: - at least this big. initModel = { selectedCategory = "Vacantion" , context = "root/Work" , abstractSyntaxTree = [ {…
AIon
  • 12,521
  • 10
  • 47
  • 73
9
votes
3 answers

Several inputs and arguments with onInput in Elm

I'm experimenting a little with Elm. Right now I have several input range on the screen and I want to control individually their values, but I don't know how to distinct between them (in Js I would send the ID and the VALUE of the input on the…
Trajan
  • 370
  • 1
  • 2
  • 8
9
votes
1 answer

Update value in a recursive type - elm lang

I have a tree like structure of text nodes that might have another text nodes as children, and I need to update one value in it. What's the easiest way to update text node that's somewhere deep in that tree (or it is not in that tree at all)? In a…
ondrej
  • 967
  • 7
  • 26
9
votes
3 answers

Using preventDefault in Elm

How do I use preventDefault in elm? Say on a keyboard event: keyDown keyCode model = case keyCode of 13 -> -- Enter key model if we don't want the default behaviour? Html.Events has methods for it, but I don't understand…
swelet
  • 8,192
  • 5
  • 33
  • 45
9
votes
2 answers

Type constraints in Elm

According to What does comparable mean in Elm? comparable is built-in type constraint that can be used to limit type variables to those built-in types that are, well, comparable. The following questions comes to mind (and are not so easy to find…
Tomas Kulich
  • 14,388
  • 4
  • 30
  • 35
9
votes
1 answer

how to access image data in Elm?

How do we get the Pixel data from images in Elm? Here in JavaScript, is code to get the color of a set of pixels in a figure (taken from here) var image = new Image; image.src = "starry-night.jpg"; var canvas =…
john mangual
  • 7,718
  • 13
  • 56
  • 95
9
votes
2 answers

how to read content of contentEditable div?

I use a contentEditable div, and I want to access its content after the user has modified it (onBlur). How can I access the innerHtml or textContent of the DOM element ? Any idea ? Here is a simple example : import Html exposing (div, text) import…
Pierre Carbonnelle
  • 2,305
  • 19
  • 25
9
votes
2 answers

elm generate random number

I want to generate a random int between two values in elm. Something like this: nb = random(0, 10) I have read the doc and multiple post. The best answer was from this stackoverflow post gen = Random.int 0 10 seed0 = Random.initialSeed…
BoumTAC
  • 3,531
  • 6
  • 32
  • 44
9
votes
4 answers

Elm: Type alias for JSON with "type" property

I have some JSON with a "type" property that I want to import into Elm. e.g., { "id": "abc", "type": "thing" } However if I define a type alias with type as a property, the compiler complains. e.g., type alias Foo = { id: String , type:…
noah
  • 21,289
  • 17
  • 64
  • 88
9
votes
2 answers

How do you print a List in Elm?

How do I convert a value of type List to a String in Elm? Basically I'm looking for a function with the signature a -> String or List -> String. Example Let's say I have a function intAverage: intAverage l = case l of [] -> 0 otherwise ->…
qff
  • 5,524
  • 3
  • 37
  • 62