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
16
votes
3 answers

What does comparable mean in Elm?

I'm having trouble understanding what exactly a comparable is in Elm. Elm seems as confused as I am. On the REPL: > f1 = (<) : comparable -> comparable -> Bool So f1 accepts comparables. > "a" "a" : String > f1 "a" "b" True : Bool So…
Mark Bolusmjak
  • 23,606
  • 10
  • 74
  • 129
16
votes
3 answers

Does 'foldp' violate FP's no mutable state principle?

I'm learning about Elm from Seven More Languages in Seven Weeks. The following example confuses me: import Keyboard main = lift asText (foldp (\dir presses -> presses + dir.x) 0 Keyboard.arrows) foldp is defined as: Signal.foldp : (a -> b -> b) ->…
Marcel
  • 367
  • 1
  • 12
15
votes
2 answers

What is the 'msg' in 'HTML msg' in Elm actually?

I'm teaching myself elm and see (of course) many references to Html msg-- I understand that this is a 'parameterised type', that is, that (as I understand it), the constructor of the type Html takes a parameter -- much as List Char does. OK. But…
Cerulean
  • 5,543
  • 9
  • 59
  • 111
15
votes
4 answers

Is it possible to iterate over union type in Elm?

I have a type union of colors that I want to render to the user. Is it possible to iterate over all type union values? type Color = Red | Blue | Green | Black colorToStirng color = case color of Red -> "red" Blue -> "blue" …
ondrej
  • 967
  • 7
  • 26
15
votes
1 answer

Is the dollar operator ($) supported in elm?

In Haskell, you can use the $ operator to clean up bits of code, removing the need for parens. Does elm support this operator, or something like it? I can define it myself but I was hoping that this was something built-in. Here's how it…
Conrad.Dean
  • 4,341
  • 3
  • 32
  • 41
15
votes
3 answers

How to get query parameters in Elm?

In my Elm program, I'd like to initialize my model based on the query string. For example, if the query string is ?w=3&h=5 I'd like to have: initialModel = { width = 3 , height = 5 } Is that possible to achieve this in Elm, or the only way…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
14
votes
3 answers

Concise way of updating a nested value inside a record in Elm (0.18)

I am looking for a concise way of updating a nested value inside a record in Elm (0.18). Given the following example: person = { name = "Steven", address = { country = "Spain", city = "Barcelona" } } I can update person.name to "Steve" using the…
jakubr
  • 305
  • 1
  • 8
14
votes
2 answers

Handling multiple match cases with single statement in Elm

I know in Scala you can handle multiple patterns with a single expression, is something like this possible in Elm? l match { case B(_) | C(_) => "B" }
Max Semikin
  • 974
  • 1
  • 11
  • 19
14
votes
6 answers

Cmd to simply go to a new webpage in Elm

Is there a way to simply go to a new webpage in Elm, similar to clicking on a link? I have a button that when clicked I want to take the user to another webpage. I know I could make that an a element and use CSS to style it like a button. However,…
at.
  • 50,922
  • 104
  • 292
  • 461
14
votes
6 answers

How do I get the current time in Elm 0.17/0.18?

I had asked this question already: How do I get the current time in Elm? And answered it by writing my own (now deprecated) variant of start-app: http://package.elm-lang.org/packages/z5h/time-app/1.0.1 Of course the Elm architecture has since…
Mark Bolusmjak
  • 23,606
  • 10
  • 74
  • 129
14
votes
3 answers

Local Storage or other data persistence in elm

I am just beginning to look at Elm with the idea of building a simple web application with it. My idea would require to persist some user data in the browser. Is there a way to handle data persistence directly with Elm? For example in browser…
marcosh
  • 8,780
  • 5
  • 44
  • 74
14
votes
2 answers

How to filter out "Nothing" values from Elm Array?

I'd like to define the following function: compactAndConvertToList : Array (Maybe String) -> List String This function should remove all Nothing appearances in the given array, and convert it to List. I came up with the solution below, but it feels…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
14
votes
2 answers

Right way to forcibly convert Maybe a to a in Elm, failing clearly for Nothings

Okay, what I really wanted to do is, I have an Array and I want to choose a random element from it. The obvious thing to do is get an integer from a random number generator between 0 and the length minus 1, which I have working already, and then…
betaveros
  • 1,360
  • 12
  • 23
13
votes
1 answer

Error when convert Http.Error to String with toString in Elm 0.19

I am working on an Elm task to decode the JSON from API. The problem I met is the decoder I've written is not matched the JSON so I want to show the error. But I cannot convert the error message from #Http.Error# type to #String# type in Elm with…
bird
  • 1,872
  • 1
  • 15
  • 32
13
votes
1 answer

How to do routing/navigation in Elm without the # (hash) in the URL?

Using the UrlParser.parseHash function i was able to successfully parse the following url: http://localhost:8000/MyRepl.elm/#home/something-else The behavior is as expected, when i copy paste this in the browser and hit enter - the app loads with…
AIon
  • 12,521
  • 10
  • 47
  • 73